无法写入变量(ASM)
我正在尝试学习汇编程序并遵循教程,第一个示例运行得很好。我了解一些基础知识,但我在变量方面遇到问题。这是我试图编译的代码:
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
它在“输入数据库”处崩溃,并显示“无效参数”。如果我将其更改为“input db”“”,那么它会在“mov input,al”处崩溃,声称“无效操作数”。我将其更改为以下内容,现在可以使用了。
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
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 operands". 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mov input, al
行尝试将 al 移动到由input db 0
行定义的值,例如编译器将其转换为mov 0, al
代码>.你想要做的是将 al 移动到 位置“输入”,所以我猜(ASM 编码对我来说是前一段时间)mov [input], al
或mov byte ptr:[input], al
效果会更好。编辑:这就是为我显示“(a)”的内容。运行适用于 Windows 的 CrunchBang Linux/Wine/FASM。
The line
mov input, al
tries to move al into the value defined by the lineinput db 0
, e.g. the compiler translates it intomov 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
ormov byte ptr:[input], al
would work better.Edit: this is what displays "(a)" for me. Running CrunchBang Linux/Wine/FASM for windows.