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.opi@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
新闻热点
疑难解答