Skip to content

Instantly share code, notes, and snippets.

@uttaravadina
Forked from GustavoARSilva/tiny_program.s
Created February 19, 2021 21:26
Show Gist options
  • Save uttaravadina/a318123848c6c4eb09b1d7ba10f8ab0d to your computer and use it in GitHub Desktop.
Save uttaravadina/a318123848c6c4eb09b1d7ba10f8ab0d to your computer and use it in GitHub Desktop.
Tiny Assembly program
@ This program counts all the even numbers cointained in the range from 0 to 10
@ in reverse order, this is: 10 + 8 + 6 + 4 + 2 = 30
@ Constants definition.
.equ STACK_TOP, 0x20000800
.text
@ The symbol _start is required by the GNU Linker to specify
@ the first instruction to be executed in a program.
.global _start
.code 16 @ Indicates the program code is in Thumb.
.syntax unified @ Indicates that the unified assembly
@ language syntax is used.
_start:
.word STACK_TOP, main
.type main, function @Declares that the symbol main is a function.
main: @ Start of main program.
@ Initialize registers.
mov r0, #10 @ Starting loop counter value.
mov r1, #0 @ Starting result.
@ Calculated 10+8+6+4+2.
loop:
add r1, r0 @ R1 = R1 + R0
subs r0, #2 @ Decrement R0, update flag ('S' suffix).
bne loop @ If result not zero jump to loop.
@ Result is now in R1
deadloop:
b deadloop @ Infinite loop.
.end @ End of file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment