%include "CONSTANTS.h" section .data DataFormat: db `R14 holds %\#qx\n`,0 FlagFormat: db `The current flag register holds %\#qb\n`,0 CaryFormat: db `\tThe carry flag is %\#qb\n`,0 ParityFormat: db `\tThe parity flag is %\#qb\n`,0 ZeroFormat: db `\tThe zero flag is %\#qb\n`,0 SignFormat: db `\tThe sign flag is %\#qb\n`,0 OverflowFormat: db `\tThe Overflow flag is %\#qb\n`,0 endl: db `\n`,0 CARRY_FLAG: dq 0x1 PARITY_FLAG: dq 4h ZERO_FLAG: dq 40h SIGN_FLAG: dq 80h OVERFLOW_FLAG: dq 800h section .bss section .text global main main: ; do some math to make r14 hold a 1, or odd parity mov r14, 0 inc r14 ; save the flag register and put it in rsi pushfq pop r12 call PrintFlags ; do some math to make r14 hold a 3, or even parity inc r14 inc r14 pushfq pop r12 call PrintFlags ; let's get a zero sub r14, 3 pushfq pop r12 call PrintFlags ; make it negative dec r14 pushfq pop r12 call PrintFlags ; let's make an overflow mov R14, 7fffffffffffffffh add R14, 1 pushfq pop r12 call PrintFlags jmp Exit PrintFlags: push R12 mov rsi, r14 mov rdi, DataFormat call CallPrintf ; save the flags in r12 mov rsi, r12 mov rdi, FlagFormat call CallPrintf mov rsi, r12 and rsi, [CARRY_FLAG] mov rdi, CaryFormat call CallPrintf mov rsi, r12 and rsi, [PARITY_FLAG] mov rdi, ParityFormat call CallPrintf mov rsi, r12 and rsi, [ZERO_FLAG] mov rdi, ZeroFormat call CallPrintf mov rsi, r12 and rsi, [SIGN_FLAG] mov rdi, SignFormat call CallPrintf mov rsi, r12 and rsi, [OVERFLOW_FLAG] mov rdi, OverflowFormat call CallPrintf mov rdi, endl; call CallPrintf pop r12 ret