0

这是我学习 NASM 和汇编语言的第二天,所以我决定写一种计算器。问题是当用户输入操作时,程序不比较它。我的意思是比较,但它不认为字符串相等。我google了很多,但没有结果。我的问题可能是什么?这是来源

operV   resb    255  ; this is declaration of variable later used to store the input, in .bss of course

mov rax, 0x2000003         ;here user enters the operation, input is "+", or "-"
mov rdi, 0
mov rsi, operV
mov rdx, 255
syscall

mov rax, operV             ; here is part where stuff is compared
mov rdi, "+"         
cmp rax, rdi
je add

mov rdi, "-"
cmp rax, rdi
je substr
;etc...
4

1 回答 1

0

当您提交此类信息时,您也可以按回车键。将 rdi 更改为 "+", 在 Linux 上为 10,或在 Windows 上更改为 "+", 11

昨晚在梦中找到了答案。

operV resd 4; Resd because registers are a dword in size, and we want the comparison to be as seamless ass possible, you can leave this as 255, but thats a little excessive as we only need 4

mov rax, 0x2000003
mov rdi, 0
mov rsi. operV
mov rdx, 4 ;You only need 4 bytes (1 dword) as this is all we are accepting (+ and line end, then empty space so it matches up with the register we are comparing too) you can leave this as 255 too, but again, we only need 4
syscall

mov rax, operV
mov rdi, "x", 10
cmp dword[rax], rdi ; You were comparing the pointer in rax with rdi, not the content pointed to by rax with rdi. now we are comparing the double word (4 bytes) at the location pointed too by rax (operV) and comparing them. Instead of comparing the location of operV with the thing you want.
je add

这就是所做的更改:P

于 2012-10-30T16:40:35.767 回答