Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
Created June 1, 2019 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinhooke/ca41e1c24a53a2be97eb253a8989923c to your computer and use it in GitHub Desktop.
Save kevinhooke/ca41e1c24a53a2be97eb253a8989923c to your computer and use it in GitHub Desktop.
ARM ASM nested loop hello world
.global main
main:
MOV R4, #3 @ init outer line counter =3
_outerloop:
MOV R3, R4 @ init word loop counter with current value of outer counter
_wordloop:
MOV R7, #4 @ syscall 4: output to stdout
MOV R0, #1 @ stdout
MOV R2, #6 @ length of string
LDR R1, =output
SWI 0
SUB R3, R3, #1 @ decrement word loop counter
CMP R3, #0
BNE _wordloop
@print newline
MOV R7, #4 @ syscall 4: output to stdout
MOV R0, #1 @ stdout
MOV R2, #1 @ length of string
LDR R1, =eol
SWI 0
SUB R4, R4, #1 @ decrement outer counter
CMP R4, #0
BNE _outerloop
_exit:
MOV R1, #0
MOV R7, #1
SWI 0
.data
output:
.asciz "Smile!"
eol:
.asciz "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment