1. 编写源文件:hello.S
.data
msg:
.ascii "Hello, ARM!\n"
len = . - msg
.text
.global _start
_start:
/*Syscall write(int fd, const void *buf, size_t count)*/
mov %r0, $1 /*输出到stdout,stdout的设备描述符为1*/
ldr %r1, =msg /*buf=msg*/
ldr %r2, =len /*count=len*/
mov %r7, $4 /*syscall 4*/
swi $0 /*invoke syscall*/
/*Syscall exit*/
mov %r0, $0
mov %r7, $1
swi $0
2. 编译链接:
arm-linux-androideabi-as -o hello.o hello.S
arm-linux-androideabi-ld -s -o hello hello.o
注:如果安装了android-ndk,那么可在toolchains目录里面找到arm-linux-androideabi-as和arm-linux-androideabi-ld一起其他的一些工具
3. 拷贝到android设备上运行:
adb push hello /data/local/tmp/hello
adb shell /data/local/tmp/hello
4. 查看运行结果:
Hello, ARM!
原文出处:http://peterdn.com/post/e28098Hello-World!e28099-in-ARM-assembly.aspx