X86-assembly/Instructions/test
Jump to navigation
Jump to search
You are here: | test
|
Description
The test instruction is identical to the and instruction except it does not affect operands.
Syntax
test destination, source
Examples
Example 1
.text:00401437 mov ecx, 1Ch ; ecx = 28 (counter)
.text:0040143C
.text:0040143C get_byte:
.text:0040143C
.text:0040143C shr ebx, 1
.text:0040143E mov edx, 0
.text:00401443 mov eax, ebx
.text:00401445 mov esi, 1Ah
.text:0040144A div esi
.text:0040144C test ecx, 1 ; \ will take the jump
.text:00401452 jz short add_97 ; / when ecx is even
.text:00401454 add edx, 41h ; jump here when ecx is odd
.text:00401457 mov [edi], dl
.text:00401459 inc edi
.text:0040145A loop get_byte ; ecx -= 1
.text:0040145C jmp short go_on
.text:0040145E ; ---------------------------------------------------------------------------
.text:0040145E
.text:0040145E add_97:
.text:0040145E add edx, 61h
.text:00401461 mov [edi], dl
.text:00401463 inc edi
.text:00401464 loop get_byte ; ecx -= 1
|
|
Example 2
test cl, cl ; set ZF to 1 if cl == 0
je 0x804f430 ; jump if ZF == 1
Example 3
test eax,eax ; set SF to 1 if eax < 0 (negative)
js error ; jump if SF == 1