-1

I am trying to create a program that greets the user with their name. The user enters their name after a prompt and the they are greeted along with their name. I have already tried using this code but it fails and throws error on line 21.

The error message states: (21) wrong parameters: LEA Dx,name (21) probably no zero prefix for hex; or no 'h' suffix; or wrong addressing; or undefined var: name

Here's the code

.MODEL SMALL                                 
.STACK 100                                   

.DATA                                        
    msg db "Hello! Please enter your name:$" 
    newline db 13,10,'$'                     
    greeting db "Wellcome!$"                   
    name db 80, 0, 78 DUP('$')
   
.CODE                                        

main PROC                                    
    ; Prompt
    MOV Ax,@DATA                             
    MOV Ds,Ax                               
    LEA Dx,msg                               
    MOV Ah,09h                               
    INT 21h                                 

    ; Input
    LEA Dx,name       (throws error)                       
    MOV AH,0AH                               
    INT 21h                                  

   
    ; Check if ENTER is pressed
    CMP Al,13                               
    JE Display                              
 
    ; Newline
    LEA Dx,newline
    MOV Ah,09h
    INT 21h
    
    ; Print Greeting                                                                           
    Display: MOV AH,09h                      
    LEA Dx,name+2
    ;MOV Dl,Al                                
    INT 21H                                  
    
    Exit:    
    MOV Ah,4Ch                              
    INT 21h                                  
main ENDP

END main    





lool
  • 345
  • 1
  • 6
  • 11

2 Answers2

1

it fails is not a useful description. When you want to use Int 21/AH=0Ah buffered input, the first buffer byte has to be initialized with its size, for instance name db 80, 0, 78 DUP('$')
Also remove the instruction MOV Dl,Al which damages DX in ; Print Greeting.

vitsoft
  • 5,515
  • 1
  • 18
  • 31
  • I initialized buffer byte as you said but I keep keep getting the same error.(21) wrong parameters: LEA Dx,name (21) probably no zero prefix for hex; or no 'h' suffix; or wrong addressing; or undefined var: name – lool Mar 31 '21 at 07:45
  • 2
    Perhaps LEA requires square brackets in memory-variable specification, just like most other assemblers do. Try `LEA DX,[name]` or `MOV DX,name`. Also check if `name` is not a reserved word in the tool which you use. – vitsoft Mar 31 '21 at 08:25
  • yes, `name` is a reserved word in MASM-style assemblers. [Why is the variable name "name" not allowed in assembly 8086?](https://stackoverflow.com/q/52955216) – Peter Cordes Mar 17 '23 at 06:07
0

try this. name not accepted use name1

    jmp start
    
    name1 db 80, 0, 78 DUP('$')
    msg db "Hello! Please enter your name:$" 
    newline db 13,10,'$'                     
    greeting db "Wellcome! $"                   
    
   
    start:                                
    ; Prompt
    MOV Ax,@DATA                             
    MOV Ds,Ax                               
    LEA Dx,msg                               
    MOV Ah,09h                               
    INT 21h                                 

    ; Input
    lea dx, name1     
    MOV AH,0AH                               
    INT 21h                                  

    LEA Dx,newline
    MOV Ah,09h
    INT 21h
    
    lea dx, greeting
    mov ah, 09h
    int 21h
   
    MOV AH,09h                      
    LEA dx, name1+2                               
    INT 21H                     
             
    
    Exit:    
    MOV Ah,4Ch                              
    INT 21h                                  
DChiTown
  • 1
  • 2