Skip to content

Instantly share code, notes, and snippets.

@GustavoARSilva
Created December 24, 2011 05:24
Show Gist options
  • Save GustavoARSilva/1516429 to your computer and use it in GitHub Desktop.
Save GustavoARSilva/1516429 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