代码编译得很好[ NASM
]
但是一旦我输入我的第一个值,它就会崩溃
我不知道出了什么问题,目标是输入一个字符串并输出字符串的反转,如果用户说是('Y'或'y'),则一直循环重复
**.DATA
; Initialized Data Definitions
strlength EQU 40
PromptStr dd "Please input a string (must be less than 40 characters long): ", 0
OutputStr dd "The reverse string is: ", 0
AgainStr dd "Would you like ot try again? ('Y' or 'y' for yes): ", 0
.UDATA
; Uninitialized Data Definitions
string resb strlength
.CODE
; Program Code
.STARTUP
nwln ; start output at a new line
PutStr PromptStr
nwln
while:
GetStr string
mov EBX, string
loop_in:
push dword[EBX]
add EBX, 4
cmp dword[EBX], 0
jnz loop_in
loop_out:
XOR EBX, EBX
pop EBX
PutCh [EBX]
cmp dword[EBX], 0
jnz loop_out
nwln
PutStr AgainStr
GetStr EBX
mov AL, [EBX]
cmp AL, 'Y'
jz while
cmp AL, 'y'
jz while
Pause
.EXIT**
我将第一个循环更改为
loop_in:
mov AL, [EBX]
push byte[AL]
add EBX, 4
cmp byte[AL], 0
jnz loop_in
我收到此错误“错误:无效的有效地址”
当我更改为“字节”时
loop_in:
push byte[EBX]
add EBX, 4
cmp byte[EBX], 0
jnz loop_in
我收到“错误:操作码和操作数的无效组合”
对于行 {add EBX, 4}
所以我改变了
loop_in:
push EBX
inc EBX
cmp byte[EBX], 0
jnz loop_in
loop_out:
XOR EBX, EBX
pop EBX
PutCh [EBX]
cmp byte[EBX], 0
jnz loop_out
现在它编译了,我做到了这一点
Please input a string (must be less than 40 characters long):
asdf
fdsaêë
在它崩溃到 Windows 之前