-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfizzbuzz.asm
75 lines (59 loc) · 1.11 KB
/
fizzbuzz.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# FizzBuzz Implementation in x64 ASM For Linux
# matthew - October 21, 2019
#
# "Write a program that prints the numbers from 1 to 100. But for multiples of three print
# "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which
# are multiples of both three and five print "FizzBuzz"."
global _start
extern printf
extern exit
section .text
_start:
mov rbx, 1
loop:
xor r12, r12
mov rax, rbx
xor rdx, rdx
mov rcx, 3
div rcx
mov rdi, rdx
mov rax, rbx
xor rdx, rdx
mov rcx, 5
div rcx
mov r13, rdx
cmp rdi, 0
jne checkBuzz
printFizz:
mov r12, 1
mov rdi, fizz
xor rax, rax
call printf
checkBuzz:
cmp r13, 0
jne printNumber
printBuzz:
mov r12, 1
mov rdi, buzz
xor rax, rax
call printf
printNumber:
cmp r12, 0
jne endLoop
mov rdi, interger
mov rsi, rbx
xor rax, rax
call printf
endLoop:
mov rdi, newLine
call printf
add rbx, 1
cmp rbx, 101
jne loop
mov rdi, 0
call exit
section .rodata
fizz db "Fizz", 0
buzz db "Buzz", 0
interger db "%u", 0
newLine db 10