Created
March 25, 2013 21:20
-
-
Save sbp/5240868 to your computer and use it in GitHub Desktop.
Display the binary value of the x86 FLAGS register on boot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bits 16 | |
start: | |
; Set up 512 bytes of stack space. More than plenty! | |
mov ax, 0x07C0 ; This is 0x7C00 >> 4 | |
add ax, 64 ; (512 + 512) / 16, for some weird offset crap | |
mov ss, ax ; SS is the stack segment | |
mov sp, 512 ; SP is the stack pointer | |
; Call the main routine | |
call print_flags | |
; We're finished, so loop-a-noop | |
jmp $ | |
print_flags: | |
pushfw ; Push x86 FLAGS register to the stack | |
pop ax ; Pop x86 FLAGS register from stack to AX | |
; Note that MOV AX, EFLAGS doesn't work for some reason | |
; Call the AX register to binary display routine | |
call ax2bin | |
ret | |
; Derived from code by NASM developer, Frank Kotler | |
; http://forum.nasm.us/index.php?topic=1371.0 | |
ax2bin: | |
push cx | |
push dx | |
mov cx, 16 | |
.top: | |
rcr ax, 1 ; Rotate and set the carry with what we rotated off | |
mov dl, "0" ; Set DL to "0", the default value | |
adc dl, 0 ; If the carry bit was set by the RCR, increase the "0" byte by one to "1" | |
push ax ; Save AX | |
mov ah, 0x0A ; 0x0A is the "print byte at cursor" argument to INT 0x10 | |
mov al, dl ; Our result is in DL, but INT 0x10 uses AL | |
int 0x10 ; Print the byte | |
pop ax ; Restore AX | |
loop .top | |
pop dx | |
pop cx | |
ret | |
times 510 - ($ - $$) db 0 | |
dw 0xAA55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment