不用链接C库的裸程序,向标准输出打印hello并调用exit退出:
.section .rodata
hellostr:
.ascii "hello\n"
.section .text
.global _start
_start:
mov x0, #1
ldr x1, =hellostr
mov x2, #6
mov x8, #64 //syscall write
svc #0
mov x0, #0
mov x8, #93 //syscall exit
svc #0
all:
as main.s -o main.o
ld main.o -o a.out
rm main.o
链接C库,调用printf打印hello并退出:
.section .rodata
hellostr:
.ascii "hello\n"
.section .text
.global _start
_start:
ldr x0, =hellostr
bl printf
mov x0, #0
bl exit
all:
as main.s -o main.o
ld -dynamic-linker /lib/ld-linux-aarch64.so.1 -lc main.o -o a.out
rm main.o
$ ldd a.out
linux-vdso.so.1 (0x0000007fa9beb000)
libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0

最低0.47元/天 解锁文章





