用户输入的NASM字符串不比较

时间:2012-10-30 16:17:00

标签: macos assembly nasm intel

这是我第二天学习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...

1 个答案:

答案 0 :(得分:0)

您提交此类信息时也会按Enter键。将rdi更改为“+”,将10更改为Linux,或“+”,11更改为Windows

昨晚在梦中找到了答案。

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

相关问题