Last active
November 5, 2022 17:02
-
-
Save jonatan1609/f1920ff484d1e4bc7d30a85026f65b1d to your computer and use it in GitHub Desktop.
A small 32bit fizzbuzz binary
This file contains 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
section .text | |
global _start | |
_start: | |
mov ecx, n | |
f: | |
push ecx | |
neg ecx | |
add ecx, n | |
add ecx, 1 | |
push ecx | |
mov edx, 0 | |
mov eax, ecx | |
mov ecx, 3 | |
idiv ecx | |
test edx, edx | |
pop ecx | |
jz fi | |
push ecx | |
mov edx, 0 | |
mov eax, ecx | |
mov ecx, 5 | |
idiv ecx | |
test edx, edx | |
pop ecx | |
jz bu | |
call pn | |
jmp do | |
fi: | |
mov ecx, fizz | |
mov edx, 6 | |
call p | |
jmp do | |
bu: | |
mov ecx, buzz | |
mov edx, 6 | |
call p | |
do: | |
pop ecx | |
loop f | |
mov edx, 2 | |
mov ecx, newline | |
call p | |
mov ebx, 0 | |
mov eax, 1 | |
int 0x80 | |
p: | |
mov ebx, 1 | |
mov eax, 4 | |
int 0x80 | |
ret | |
pn: | |
push ecx | |
mov ebx, ecx | |
mov ecx, digits | |
lea ecx, [ecx+ebx-1] | |
mov edx, 1 | |
mov ebx, 1 | |
mov eax, 4 | |
int 0x80 | |
mov ecx, space | |
mov edx, 2 | |
call p | |
pop ecx | |
ret | |
section .rodata | |
fizz db "FIZZ", 0x20, 0 | |
buzz db "BUZZ", 0x20, 0 | |
digits db "123456789", 0 | |
space db 0x20, 0 | |
newline db 0x0a, 0 | |
n equ 10 |
This file contains 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
Compile and run: | |
nasm -f elf32 fizzbuzz.asm && ld -m elf_i386 --strip-all -o fizzbuzz fizzbuzz.o -n -z max-page-size=0x1000 -nostdlib && ./fizzbuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment