Skip to content

Instantly share code, notes, and snippets.

@aarroyoc
Created August 2, 2022 19:53
Show Gist options
  • Save aarroyoc/a8514bec7fc8e8d4789ca4c45178e293 to your computer and use it in GitHub Desktop.
Save aarroyoc/a8514bec7fc8e8d4789ca4c45178e293 to your computer and use it in GitHub Desktop.
Fibonacci Numbers ARM64 Linux
.data
fibs: .quad 0,0,0,0,0,0,0,0,0,0,0,0
size: .quad 12
printf_str: .asciz "%d\n"
head: .ascii "The Fibonacci numbers are:\n"
head_len = . - head
.text
.global main
main:
ldr x0, =fibs
ldr x5, =size
ldr x5, [x5]
mov x2, #1
str x2, [x0]
str x2, [x0, #8]
add x1, x5, #-2
loop:
ldr x3, [x0]
ldr x4, [x0, #8]
add x2, x3, x4
str x2, [x0, #16]
add x0, x0, #8
add x1, x1, #-1
cmp x1, #0
bgt loop
print:
mov x0, #1
ldr x1, =head
ldr x2, =head_len
mov w8, #64
svc #0
ldr x21, =size
ldr x21, [x21]
ldr x20, =fibs
out:
ldr x0, =printf_str
ldr x1, [x20]
bl printf
add x20, x20, #8
add x21, x21, #-1
cmp x21, #0
bgt out
exit:
mov x0, #0
mov w8, #93
svc #0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment