arm64 hello world
环境
win10系统 使用wsl2
wsl --install
重启
# 更新软件源
sudo apt update
# 安装交叉编译器(在 x86 上生成 ARM64 代码)
# 安装 QEMU 用户态模拟器(让 ARM64 程序直接在你的 CPU 上跑)
sudo apt install gcc-aarch64-linux-gnu qemu-user-static binutils-aarch64-linux-gnu -y
# 验证安装是否成功
aarch64-linux-gnu-gcc --version
qemu-aarch64-static --version
hello.s
ai写的
// hello.s
.section .data
msg: .ascii "Hello ARM64 from Win 10!\n"
len = . - msg // 计算字符串长度
.section .text
.global _start
_start:
// 1. 调用 write(int fd, const void *buf, size_t count)
mov x0, #1 // 参数1: fd = 1 (标准输出)
ldr x1, =msg // 参数2: buf = 字符串地址
mov x2, len // 参数3: count = 字符串长度
mov x8, #64 // write 的系统调用号是 64
svc #0 // 执行系统调用
// 2. 调用 exit(int status)
mov x0, #0 // 参数1: status = 0
mov x8, #93 // exit 的系统调用号是 93
svc #0 // 执行系统调用
编译
# 1. 汇编 (Assemble)
aarch64-linux-gnu-as -o hello.o hello.s
# 2. 链接 (Link)
aarch64-linux-gnu-ld -o hello hello.o
# 3. 运行 (Execute)
qemu-aarch64-static ./hello

浙公网安备 33010602011771号