Created
August 2, 2017 19:58
-
-
Save rigred/e3665efe3a4cd82853e3956e44f0af9b to your computer and use it in GitHub Desktop.
A very small fizzbuzz program written in IA-32 assembly
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
; fizzbuzz_tiny.asm | |
BITS 32 | |
org 0x08048000 | |
ehdr: ; Elf32_Ehdr | |
db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident | |
times 8 db 0 | |
dw 2 ; e_type | |
dw 3 ; e_machine | |
dd 1 ; e_version | |
dd _start ; e_entry | |
dd phdr - $$ ; e_phoff | |
dd 0 ; e_shoff | |
dd 0 ; e_flags | |
dw ehdrsize ; e_ehsize | |
dw phdrsize ; e_phentsize | |
dw 1 ; e_phnum | |
dw 0 ; e_shentsize | |
dw 0 ; e_shnum | |
dw 0 ; e_shstrndx | |
ehdrsize equ $ - ehdr | |
phdr: ; Elf32_Phdr | |
dd 1 ; p_type | |
dd 0 ; p_offset | |
dd $$ ; p_vaddr | |
dd $$ ; p_paddr | |
dd filesize ; p_filesz | |
dd filesize ; p_memsz | |
dd 5 ; p_flags | |
dd 0x1000 ; p_align | |
phdrsize equ $ - phdr | |
_start: | |
sub eax, 104 | |
sub ebx, 99 | |
lea esp, [esp + 4*eax] | |
mov edi, esp | |
push dword 0x7a7a7542 ; Buzz | |
push dword 0x7a7a6946 ; Fizz | |
mov edx, esp | |
.loop lea ecx, [ebx + 100] | |
mov eax, ecx | |
aam 3 | |
mov eax, ecx | |
setz ch | |
aam 5 | |
setz cl | |
jecxz .num | |
and cl, ch | |
xor ch, 1 | |
inc cl | |
movzx esi, ch | |
movzx ecx, cl | |
lea esi, [edx + 4*esi] | |
rep movsd | |
jmp .nl | |
.num lea eax, [ebx + 100] | |
aam | |
xchg al, ah | |
test al, al | |
setz cl | |
add ax, 0x3030 | |
push eax | |
lea esi, [edx + ecx - 4] | |
xor cl, 1 | |
inc ecx | |
rep movsb | |
pop eax | |
.nl mov al, 10 | |
stosb | |
inc ebx | |
jle .loop | |
lea eax, [ebx + 3] | |
sub edi, edx | |
lea ecx, [edx + 8] | |
lea edx, [edi - 8] | |
int 0x80 | |
mov eax, ebx | |
dec ebx | |
int 0x80 | |
filesize equ $ - $$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To compile use