Commit cb537104 authored by Ollie Rhodes's avatar Ollie Rhodes

Upload New File

parent f84190b1
section .bss
digitSpace resb 100
digitSpacePos resb 8
section .data
fizzText db "Fizz"
bangText db "Bang"
title db "FizzBang Demo", 10
section .text
global _start
_start:
xor r10, r10 ;loop number
mov r11, 20 ;total iterations
;xor r12, r12 ;bang count
;xor r13, r13 ;fizz count
call _title
loopStart:
;mov rax, r10 ;moves the value of r10 (loop number) into RAX
;call _printRAX ;prints the int in RAX
;syscall
call _check3
call _check5
call _checkNone
inc r10 ;increase the loop number
cmp r10, 20 ;compare current loop number to 20
jle loopStart ;jump to loop start if loop number <= 20
mov rax, 60 ;end program
mov rdi, 0
syscall
_check3:
xor rdx, rdx ;clears rdx for division
mov rax, r10 ;moves loop no into rax
mov rbx, 3 ;sets rbx as 3
div rbx ;divides rax by 3
cmp rdx, 0 ;modulo result - remainder
je tMul ;jump if no remainder
jmp tEnd ;otherwise go to tEnd
tMul: ;goes here if it's a multiple of 3
mov rax, 1 ;prints fizz
mov rdi, 1
mov rsi, fizzText
mov rdx, 4
syscall
tEnd:
ret
_check5:
xor rdx, rdx
mov rbx, 5
mov rax, r10
div rbx
cmp rdx, 0
je fMul
jmp fEnd
fMul:
mov rdx, 1
mov rdi, 1
mov rsi, bangText
mov rdx, 4
syscall
fEnd:
ret
_checkNone:
xor rdx, rdx
mov rbx, 3
mov rax, r10
div rbx
cmp rdx, 0
jne tNo
jmp nEnd
tNo:
xor rdx, rdx
mov rbx, 5
mov rax, r10
div rbx
cmp rdx, 0
jne fNo
jmp nEnd
fNo:
mov rax, r10
call _printRAX
syscall
nEnd:
ret
_title: ;prints text in title
mov rax, 1
mov rdi, 1
mov rsi, title
mov rdx, 14
syscall
ret
; The following code was taken from an online source
; It is only used to print integers - I was unable to get this working alone
_printRAX:
mov rcx, digitSpace
mov rbx, 10
mov [rcx], rbx
inc rcx
mov [digitSpacePos], rcx
_printRAXLoop:
mov rdx, 0
mov rbx, 10
div rbx
push rax
add rdx, 48
mov rcx, [digitSpacePos]
mov [rcx], dl
inc rcx
mov [digitSpacePos], rcx
pop rax
cmp rax, 0
jne _printRAXLoop
_printRAXLoop2:
mov rcx, [digitSpacePos]
mov rax, 1
mov rdi, 1
mov rsi, rcx
mov rdx, 1
syscall
mov rcx, [digitSpacePos]
dec rcx
mov [digitSpacePos], rcx
cmp rcx, digitSpace
jge _printRAXLoop2
ret
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment