Unable to write into variable (ASM)
I'm trying to learn Assembler and following a tutorial, and the first examples worked perfectly. I know a bit of the basics, but I'm having problems with variables. Here's the code I'm trying to compile:
leftbr db "("
rightbr db ")"
input db
start:
mov ah,08
int 21h
mov input,al
output:
mov dl,leftbr
mov ah,02
int 21h
mov dl,key
int 21h
mov dl,rightbr
int 21h
exit:
mov ah,4ch
mov al,00
int 21h
It crashes at "input db" saying "invalid argument". If I change it to "input db "" " then it crashes at "mov input,al" claiming "invalid o开发者_运维百科perands". I changed it to the following and it now works.
start:
mov ah,08
int 21h
mov [input],al
output:
mov [leftbr], "("
mov [rightbr], ")"
mov dl,[leftbr]
mov ah,02
int 21h
mov dl,[input]
int 21h
mov dl,[rightbr]
int 21h
exit:
mov ah,4ch
mov al,00
int 21h
leftbr db 0
rightbr db 0
input db 0
The line mov input, al
tries to move al into the value defined by the line input db 0
, e.g. the compiler translates it into mov 0, al
. What you want to do, is move al to the position "input", so I guess (ASM coding was some time ago for me) mov [input], al
or mov byte ptr:[input], al
would work better.
Edit: this is what displays "(a)" for me. Running CrunchBang Linux/Wine/FASM for windows.
format MZ
org 0x100
jmp start
leftbr db "(", 0
rightbr db ")"
input db "a"
start:
xor ax,ax
mov ah,08
;int 21h ; commenting this line because wine doesn't seem to like it
;mov [input],al
output:
mov dl,byte [leftbr]
mov ah,02
int 21h
mov ah,02 ; not sure if ah gets modified, probably not
mov dl,[input]
int 21h
mov ah,02
mov dl,[rightbr]
int 21h
exit:
mov ah,4ch
mov al,00
int 21h
精彩评论