0

NASMとアセンブリ言語を学ぶのは2日目なので、一種の電卓を書くことにしました。問題は、ユーザーが操作を入力したときに、プログラムがそれを比較しないことです。つまり、比較しますが、文字列が等しいとは見なされません。私はたくさんグーグルで検索しましたが、結果はありません。私の問題は何でしょうか?ソースはこちら

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

そのような情報を送信するときも、Enterキーを押します。rdiを「+」に変更します。Linuxでは10、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

于 2012-10-30T16:40:35.767 に答える