无法写入变量(ASM)

发布于 2024-10-10 11:59:47 字数 662 浏览 6 评论 0原文

我正在尝试学习汇编程序并遵循教程,第一个示例运行得很好。我了解一些基础知识,但我在变量方面遇到问题。这是我试图编译的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱没勇气 2024-10-17 11:59:47

mov input, al 行尝试将 al 移动到由 input db 0 行定义的值,例如编译器将其转换为 mov 0, al代码>.你想要做的是将 al 移动到 位置“输入”,所以我猜(ASM 编码对我来说是前一段时间) mov [input], almov byte ptr:[input], al 效果会更好。

编辑:这就是为我显示“(a)”的内容。运行适用于 Windows 的 CrunchBang Linux/Wine/FASM。

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 

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 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文