the REP instruction does not check the status of the flags between repetitions; remember that it is only concerned about the count value in the ECX register.
The solution is to use the other instructions in the REP family: REPE, REPNE, REPZ, and REPNZ.
These instructions check the zero flag for each repetition and stop the repetitions if the zero flag is set.
The solution is to use the other instructions in the REP family: REPE, REPNE, REPZ, and REPNZ.
These instructions check the zero flag for each repetition and stop the repetitions if the zero flag is set.
This enables you to check strings byte by byte to determine whether they match up.
As soon as one of the character pairs does not match, the REP instruction will stop repeating.
.section .data
value1:
.ascii “This is a test of the CMPS instructions”
value2:
.ascii “This is a test of the CMPS Instructions”
.section .text
.globl _start
_start:
nop
movl $1, %eax
lea value1, %esi
leal value2, %edi
movl $39, %ecx
cld
repe cmpsb
je equal
movl %ecx, %ebx
int $0x80
equal:
movl $0, %ebx
int $0x80