Skip to content

Instantly share code, notes, and snippets.

@iximeow
Created March 22, 2017 22:21
Show Gist options
  • Select an option

  • Save iximeow/7c57cfd36134be90edec20982e11a167 to your computer and use it in GitHub Desktop.

Select an option

Save iximeow/7c57cfd36134be90edec20982e11a167 to your computer and use it in GitHub Desktop.
x86 parity flag
; nasm -f macho -o pf.o
; ld pf.o
; ./a.out
;
; this probably works on linuxes too, i think exit and write should be the same.
;
; should produce:
; tears (2)
; 00000246 <-- eax = 0, xor by 0
; 00000206 <-- xor ax, 0x0100
; 00000246 <-- eax = 0, xor by 0
; 00000202 <-- xor ah, 0x01. Parity flag cleared. :)
section .text
global start
start:
mov eax, 0
xor eax, 0
pushfd
call print_reg
xor ax, 0x0100
pushfd
call print_reg
mov eax, 0
xor eax, 0
pushfd
call print_reg
xor ah, 0x01
pushfd
call print_reg
jmp end
print_reg:
push eax
mov eax, [esp + 0x8]
call print_high
shl eax, 4
call print_high
shl eax, 4
call print_high
shl eax, 4
call print_high
shl eax, 4
call print_high
shl eax, 4
call print_high
shl eax, 4
call print_high
shl eax, 4
call print_high
shl eax, 4
push dword 1
push dword newln
push dword 1
sub esp, 0x04
mov eax, 0x04
int 0x80
add esp, 0x10
pop eax
ret
end:
skip:
mov eax, 1
push 0
sub esp, 12
int 0x80
print_high:
push eax
push ebx
mov ebx, eax
shr ebx, 28
and ebx, 0x0f
add ebx, hexdigits
push dword 1
push dword ebx
push dword 1
sub esp, 0x04
mov eax, 0x04
int 0x80
add esp, 0x10
pop ebx
pop eax
ret
section .data
newln db 0x0A
hexdigits db "0123456789abcdef"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment