-
-
Save uttaravadina/a318123848c6c4eb09b1d7ba10f8ab0d to your computer and use it in GitHub Desktop.
Tiny Assembly program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ 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