SAHF Instruction
The SAHF instruction (store AH into status flags) copies AH into the low byte of the EFLAGS register.
SAHF — Store AH Register into Flags |
Usage: SAHF
|
Flag |
O
|
D
|
I
|
S
|
Z
|
A
|
P
|
C
|
|
Result |
|
|
|
* |
* |
* |
* |
* |
Transfers bits 0-7 of AH into the flags register. This includes A, C, P, S, and Z.
AH := S Z ? A ? P ? C
|
|
Clocks |
|
|
Operands |
286 |
386 |
486 |
Size Bytes |
| |
2 |
3 |
2 |
1 |
|
|
|
Setting Sign and Carry Flags |
Output |
.code
mov ebx, 0 ; Clears ebx.
mov ah, 10000001b ; Sets Sign and Carry flag.
sahf ; Loads ah into flags.
jnc L1 ; Jumps if not carry.
inc ebx ; If carry, increases ebx.
L1: jns L2 ; Jumps if not sign.
inc ebx ; If sign, increases ebx.
L2: mov eax, ebx ; Moves ebx to eax.
call WriteInt ; Prints eax.
|
|
The following instructions will be covered in detail in Chapter 6.
-
test: It performs an implied and operation between each pair of matching bits in two operands and sets the flags accordingly.
The only difference between test and and is the test does not modify the destination operand.
-
jnz: jumps if Zero flag is not set.
-
jnc: jumps if Carry flag is not set.
-
jns: jumps if Sign flag is not set.
“I’m not arguing, I’m just explaining why I’m right.”
― Unknown
|