Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; OMGWTF presents:
- ; fizzbuzz up to 100 in x86 asm (32bit)
- ; - no conditional branches
- ; - 110 bytes .text (not counting "nop")
- ; - 49 bytes .data
- ; nasm -f elf32 fb.asm && ld -m elf_i386 fb.o -o fb && ./fb
- section .text
- global _start
- _start:
- xor esi, esi ; counter
- mov ebp, len
- mov edi, [ebp+4]
- loop:
- inc esi
- xor edx, edx
- mov eax, esi
- lea ecx, [2*edi]
- div ecx
- add eax, '0'
- add edx, '0'
- mov byte [ebp+32], al
- sub eax, '1'
- shr eax, 31
- xor eax, 1
- mov ecx, eax
- mov byte [ecx + ebp+32], dl
- inc ecx
- mov byte [ecx + ebp+32], 10
- inc ecx
- mov dword [ebp], ecx
- mov eax, esi
- xor edx, edx
- lea ecx, [edi - 2]
- div ecx
- sub edx, 1
- shr edx, 31
- mov ecx, edx
- mov eax, esi
- xor edx, edx
- div edi
- sub edx, 1
- shr edx, 31
- lea ecx, [ecx + 2*edx]
- lea eax, [esi-101]
- shr eax, 30
- inc eax
- mov ebx, eax
- shr ebx, 2
- mov edx, [ebp + 4*ecx]
- mov ecx, [ebp + 4*ecx + 16]
- int 0x80 ; write(STDOUT, x0, 3);
- jmp loop
- end:
- nop
- section .data
- len dd 0, 5, 5, 9
- tab dd x0, x1, x3+4, x3
- x0 db "xxN"
- x1 db "Fizz", 10
- x3 db "FizzBuzz", 10
Advertisement
Add Comment
Please, Sign In to add comment