Skip to content

Instantly share code, notes, and snippets.

@bradfordbarr
Created May 8, 2014 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bradfordbarr/e107a74fe691ff384990 to your computer and use it in GitHub Desktop.
Save bradfordbarr/e107a74fe691ff384990 to your computer and use it in GitHub Desktop.
Adding two numbers using ARM assembly
// Assembly generally has three sections in the source
// .text - This is where all of the code lives (Flash)
// .data - This is where all variables with value go (RAM)
// .bss - This is where uninitialized variables go (RAM)
//
// Since this program is super simple I just used the .text section
.text
.word 0x20000000 // (address 0x0000.0000) This initializes the stack pointer
b start + 1 // (address 0x0000.0004) This instructs the CPU to branch to start at reset
start:
mov r0, #1 // Move the number 1 into register r0
mov r1, #2 // Move the number 2 into register r1
add r2, r1, r0 // Add r0 and r1 and store the result in r2
stop: b stop // Just loop forever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment