首页 > 学院 > 开发设计 > 正文

how to build a smallest binay in ARMv7 device?

2019-11-06 08:01:32
字体:
来源:转载
供稿:网友

Here is starting example of an assembly PRogram which just prints a single static text string. It is written in ARM assembly language and should be compiled into a really small binary we can run on any ARMv7 device.

.data

msg:    .ascii      "Hello World!/n"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 */~

$ as -o hello.o hello.S$ ld -s -o hello hello.o

pi@raspberrypi:~ $ file hellohello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped-rwxr-xr-x  1 pi pi      444 Mar  3 11:42 hello-rw-r--r--  1 pi pi      736 Mar  3 11:42 hello.o-rw-r--r--  1 pi pi      549 Mar  3 11:41 hello.S


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表