arm汇编学习(五)

新增个手写GNU语法arm的方法,以后可以狂逆狂写

hello.S文件

.data

msg:
.ascii "Hello, ARM!
"
len = . - msg

.text

.globl _start
_start:
/* syscall write(int fd, const void *buf, size_t count) */
mov %r0, $1 /* fd -> stdout */
ldr %r1, =msg /* buf -> msg */
ldr %r2, =len /* count -> len(msg) */
mov %r7, $4 /* write is syscall #4 */
swi $0 /* invoke syscall */

/* syscall exit(int status) */
mov %r0, $0 /* status -> 0 */
mov %r7, $1 /* exit is syscall #1 */
swi $0 /* invoke syscall */

记得最后加个空格或者回车,不然会报hello.S:21: Warning: partial line at end of file ignored


arm-linux-androideabi-as -o hello.o hello.S
arm-linux-androideabi-ld -s -o hello hello.o


也是个学习ARM汇编的方法
参考:
http://peterdn.com/post/e28098Hello-World!e28099-in-ARM-assembly.aspx
http://www.amccormack.net/getting-started-arm-assembly-for-android/

原文地址:https://www.cnblogs.com/moonflow/p/3244768.html