Fizz buzz
Inspired by a conversation about interview coding tasks from a list I'm on, I present the following - I considered it too long to email there. It took me longer than I expected to write; my x86 assembly is quite rusty. I'm not claiming it's pretty, but it fits in a single sector and most of the overhead is actually ELF structures.
; nasm -f elf fizzbuzz.asm ; ld -melf_i386 -s -o fizzbuzz fizzbuzz.o ; ./fizzbuzz section .data fizz db " fizz" fizzlen equ $ - fizz buzz db " buzz" buzzlen equ $ - buzz num db " " numend equ $ - 1 numlen equ $ - num nl db 0xa nllen equ $ - nl curnum db 1 section .text global _start _start: mov ax, [curnum] call printnum mov ax, [curnum] mov cx, 3 xor dx, dx div cx cmp dx, 0 jnz notfizz mov edx, fizzlen mov ecx, fizz call printstr notfizz: mov ax, [curnum] mov cx, 5 xor dx, dx div cx cmp dx, 0 jnz notbuzz mov edx, buzzlen mov ecx, buzz call printstr notbuzz: mov edx, nllen mov ecx, nl call printstr inc BYTE [curnum] cmp BYTE [curnum], 100 jle _start xor ebx, ebx mov eax, 1 int 0x80 printnum: mov edi, numend mov cx, 10 p1: xor edx, edx div cx add dx, '0' mov [edi], dl dec edi cmp ax, 0 jne p1 mov ecx, num mov edx, numlen printstr: mov ebx, 1 mov eax, 4 int 0x80 ret