Guest_imported
New member
- Jan 1, 1970
- 0
Hello. I am very new to assembly and I was messing around with a short little program to get familiar with the basics but something I thought was odd kept happening. The program is suppose to get a character from the keyboard and then display that character in this format: (character). Or if you hit escape it will say: Esc. I have 4 variables. Two contain the ( and ) another contains a string telling the user to input a character and the last one to store the input entered. I discovered, however, that if I don't declare the variables that contain the ( and ) first, instead of outputting the character like (a) it will output aa) or (aa. Can anyone please shed some light on this? I'd greatly appreciate it. Heres the code that messes up:
JMP start
;========================================
instr db "Enter A Character:",10,13,"$"
key db
leftbr db "("
rightbr db "
"
;========================================
start:
mov ah,09
mov dx,offset instr
int 21h
mov ah,08
int 21h
mov key,al
CMP key,27
JNZ print
JZ escape
print:
mov ah,02
mov dl,leftbr
int 21h
mov dl,key
int 21h
mov dl,rightbr
int 21h
JMP exit
escape:
mov ah,02
mov dl, "E"
int 21h
mov dl, "s"
int 21h
mov dl, "c"
int 21h
exit:
mov ah,4Ch
mov al,00
int 21h
JMP start
;========================================
instr db "Enter A Character:",10,13,"$"
key db
leftbr db "("
rightbr db "
;========================================
start:
mov ah,09
mov dx,offset instr
int 21h
mov ah,08
int 21h
mov key,al
CMP key,27
JNZ print
JZ escape
print:
mov ah,02
mov dl,leftbr
int 21h
mov dl,key
int 21h
mov dl,rightbr
int 21h
JMP exit
escape:
mov ah,02
mov dl, "E"
int 21h
mov dl, "s"
int 21h
mov dl, "c"
int 21h
exit:
mov ah,4Ch
mov al,00
int 21h