The Flags Register
Notes
- This is Jorgensen 2.3.1.5 and other places
- Note: Jorgensen calls this the rFlag(s) register
- Other places I have seen FLAGS
- gdb calls it eflags
- The flags register is used to communicate information from the CPU
- It is a 64 bit special purpose register
- It is usually set by math operations
- But some come from interrupts
- Jorgensen gives us a few of the bits
- carry is bit 0
- parity is bit 2
- zero is bit 6
- sign is bit 8
- But most of the bits are reserved for future use.
- Look at the table on wikipedia.
- When the CPU does anything, these flags will be set
- And set when other instruction is executed the flags are changed.
- The conditional jump instructions examine these flags.
- In gdb we can examine the flags register
-
p $eflags - Run
simple.asm - Before the first add, PF, ZF and IF
- Note that IF is the Interrupt enable Flag.
- After the first add, PF, SF, IF
- After the first inc: SF, If
- After the second inc : PF AF ZF IF
-
-
j*- Look at this cheat sheet for the jump instructions.
- Each of these will examine the flags register and jump accordingly
- We will only consider signed numbers for now.
- We will come back and look at unsigned later.
- Note: this must immediately follow the instruction that sets the flags register.
- A short side trip on labels
- The nasm page.
- letters, numbers, _, $, #, @, ~, . and ?
- must start with a letter, _ or ?
- Colon at the end is optional
- NASM supports local labels
- start with a .
- refer back to the previous non-local label
-
loop1: .top: cmp rax, 10 jge .out ... inc rax j .top .out: - It will yell at you if you don't end the label with :
- You could also do
jmp loop1.top
-
cmp- Compares two values
- First can be register, memory
- Second can be register, memory, immeiate
- But both can not be memory
- This will set the flags register but not change the values of either operand.
- It does this by subtraction.