Created
September 30, 2012 12:25
-
-
Save Leonidas-from-XIV/3806627 to your computer and use it in GitHub Desktop.
First steps in ARM assembler on Raspberry Pi
This file contains hidden or 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
#include <stdio.h> | |
int main(void) { | |
printf("Hello world!"); | |
return 0; | |
} |
This file contains hidden or 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
# 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