此问题与其他问题类似,但并非重复。我正在学习NASM(汇编)。 我的程序具有以下目标。我输入一个词(例如“ aab”)。我想将字符串中的每个字符比较为预定义的值。 这是一个片段。
;try to compare
xor rax,rax ;set iteration index to 0
lea rsi, [userpass]
back_to_loop:
cmp rsi, 'a'
je _exit
inc rsi ;increase index
jmp back_to_loop
!!!一个很好的帮助是使用这种方式来编辑程序,以便一旦在字符串中找到“ a”,迭代就会停止。如果发现完成的方法,可以根据自己的需要进行修改。
到目前为止,我的全部努力:
section .text
global _start
_start:
;read input
xor rax, rax
mov rdi, rax
mov rsi, userpass
mov rdx, rax
add rdx, 0x64 ; 100
syscall
;try to compare
xor rax,rax ;set iteration index to 0
lea rsi, [userpass]
back_to_loop:
cmp rsi, 'a'
je _exit
inc rsi ;increase index
jmp back_to_loop
_exit:
mov rax, 1
xor rbx, rbx
int 80h
section .bss
num resb 64
section .data
userpass times 100 db 0 ;input