movsb & scasb & cmpsb
将内容从rsi指向的地址搬到rdi指向的地址,b表示一次搬动一个byte,像是这样:
mov [rdi], [rsi]; 递增rdi, rsimov [rdi], [rsi]......; 此mov伪指令不可执行,来源和目的不可以都是地址将hello每次8 bytes移动到temp
section .datahello: dq 'Hello, W' dq 'orld!',10
section .bsstemp: resq 2
global _start
section .text_start: mov rsi, hello mov rdi, temp movsq ; temp="Hello, W" 使用x/s $rdi-8 movsq ; temp="orld!\n" 使用x/s $rdi-16 或 x/2gx $rsi-16 mov rax, 60 xor rdi, rdi syscall使用rep重复,先将rcx设成循环次数再执行rep movsq
section .datahello: dq 'Hello, W' dq 'orld!',10
section .bsstemp: resq 2
global _start
section .text_start: mov rsi, hello mov rdi, temp mov rcx, 2 rep movsq mov rax, 60 xor rdi, rdi syscall从rdi指向的地址跟al做cmp比对,并将rdi递增,可搭配rep/repe/repne
单次scasq判断8个bytes是否与rax内容相等
section .datahello: dq 'Hello, W' dq 'orld!',10
global _start
section .text_start: mov rdi, hello mov rax, 'Hello, W' scasq ; 使用gdb查看 i r eflags, x/s $rdi mov rax, 60 xor rdi, rdi syscall使用repne重复scasb直到遇到\0,rcx为搜索长度
section .datahello: db "hello", 0
global _start
section .text_start: mov rdi, hello xor rax, rax mov rcx, 6 repne scasb ; 最后rsi位址在\0的地方 mov rax, 60 xor rdi, rdi syscall将rdi指向的地址内容与rsi依序递增比对
cmp [rsi], [rdi] 然后将rdi递增和rsi递增
使用后rdi和rsi会被改成新的地址, 比如cmpsq会分别+8
可以搭配rep/repe/repne在相等或不相等的情况下最多重复rcx次
section .datadata1: db "abcxy"data2: db "abcqw"
global _start
section .text_start: mov rdi, data1 mov rsi, data2 mov rcx, 5 repe cmpsb ; 最後做完cmp x, q並遞增,會停在y和w mov rax, 60 xor rdi, rdi syscall