Last active
August 5, 2017 18:27
-
-
Save henrikse55/e85b54bc194cd9ac007d663ff242b086 to your computer and use it in GitHub Desktop.
I decided to do the fizzbuzz challange using assembly, this is the first thing I decided to do after hello world, there is deffinently room for improvements here
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 .data | |
Fizz db 'Fizz', 10 | |
FizzLen equ $ - Fizz | |
Buzz db 'Buzz', 10 | |
BuzzLen equ $ - Buzz | |
FizzBuzz db 'FizzBuzz', 10 | |
FizzBuzzLen equ $ - FizzBuzz | |
Three dq 3 | |
Five dq 5 | |
Fifteen dq 15 | |
section .text | |
global main | |
extern printf | |
main: | |
mov rcx, 20 | |
mov rax, 0 | |
compare: | |
inc rax | |
push rax | |
push rcx | |
mov rdx, 0 | |
idiv qword [Fifteen] | |
cmp rdx, 0 | |
je Print_FizzBuzz | |
pop rcx | |
pop rax | |
jmp Check_Buzz | |
Check_Buzz: | |
push rax | |
push rcx | |
mov rdx, 0 | |
idiv qword [Five] | |
cmp rdx, 0 | |
je Print_buzz | |
pop rcx | |
pop rax | |
jmp Check_Fizz | |
Check_Fizz: | |
push rax | |
push rcx | |
mov rdx, 0 | |
idiv qword [Three] | |
cmp rdx, 0 | |
je Print_Fizz | |
pop rcx | |
pop rax | |
jmp print | |
Print_buzz: | |
mov rax, 1 | |
mov rdi, 1 | |
mov rsi, Buzz | |
mov rdx, BuzzLen | |
syscall | |
pop rcx | |
pop rax | |
dec rcx | |
cmp rcx, 0x0 | |
jne compare | |
jmp exit | |
Print_FizzBuzz: | |
mov rax, 1 | |
mov rdi, 1 | |
mov rsi, FizzBuzz | |
mov rdx, FizzBuzzLen | |
syscall | |
pop rcx | |
pop rax | |
dec rcx | |
cmp rcx, 0x0 | |
jne compare | |
jmp exit | |
Print_Fizz: | |
mov rax, 1 | |
mov rdi, 1 | |
mov rsi, Fizz | |
mov rdx, FizzLen | |
syscall | |
pop rcx | |
pop rax | |
dec rcx | |
cmp rcx, 0x0 | |
jne compare | |
jmp exit | |
print: | |
push rax | |
push rcx | |
mov rdi, format | |
mov rsi, rax | |
xor rax, rax | |
call printf | |
pop rcx | |
pop rax | |
dec rcx | |
cmp rcx, 0x0 | |
jne compare | |
jmp exit | |
format: | |
db "%u", 10, 0 | |
exit: | |
mov rax, 60 | |
xor rdi, rdi | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment