The CMPS family of instructions is used to compare string values.
❑ CMPSB: Compares a byte value
❑ CMPSW: Compares a word (2 bytes) value
❑ CMPSL: Compares a doubleword (4 bytes) value
Each time the CMPS instruction is executed, the ESI and EDI registers are incremented or decremented by the amount of the data size compared, depending on the DF flag setting.
The CMPS instruction subtracts the destination string from the source string, and sets the carry, sign, overflow, zero, parity, and adjust flags in the EFLAGS register appropriately.
❑ CMPSB: Compares a byte value
❑ CMPSW: Compares a word (2 bytes) value
❑ CMPSL: Compares a doubleword (4 bytes) value
Each time the CMPS instruction is executed, the ESI and EDI registers are incremented or decremented by the amount of the data size compared, depending on the DF flag setting.
The CMPS instruction subtracts the destination string from the source string, and sets the carry, sign, overflow, zero, parity, and adjust flags in the EFLAGS register appropriately.
After the CMPS instruction,you can use the normal conditional jump instructions to branch, depending on the values of the strings.
.section .data
value1:
.ascii “Test”
value2:
.ascii “Test”
.section .text
.globl _start
_start:
nop
movl $1, %eax
leal value1, %esi
leal value2, %edi
cld
cmpsl
je equal
movl $1, %ebx
int $0x80
equal:
movl $0, %ebx
int $0x80