Skip to content

Instantly share code, notes, and snippets.

@Leonidas-from-XIV
Created September 30, 2012 12:25
Show Gist options
  • Save Leonidas-from-XIV/3806627 to your computer and use it in GitHub Desktop.
Save Leonidas-from-XIV/3806627 to your computer and use it in GitHub Desktop.
First steps in ARM assembler on Raspberry Pi
#include <stdio.h>
int main(void) {
printf("Hello world!");
return 0;
}
# switch to a nicer syntax
.syntax unified
# declare main as exportable (public)
.global main
# our main "function"
main:
# push return address (lr) and ip on the stack
push {ip, lr}
# put the address of the string into the r0 register
ldr r0, =message
# branch local - a function call, printf()
bl printf
# put 0 in r0 as result of the main function (return 0)
mov r0, #0
# pop the values from stack into ip and pc registers
pop {ip, pc}
# our string to print, ASCII zero terminated
message:
.asciz "Hello world!\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment