# assembly **Repository Path**: peng-langyuan/assembly ## Basic Information - **Project Name**: assembly - **Description**: aarch64 assembly - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-28 - **Last Updated**: 2025-04-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 本示例都是基于ARM64 Cortex-A 1. .section: 将代码划分位若干个段 .section .data: 用于存放已初始化的全局变量和静态变量,可读写 .section .text: 保存实际的代码段,只读 .section .bss: 用于存放未初始化的全局变量和静态变量,可读写 2. 程序的入口声明 .section .text .globl _start 3. 通用寄存器31个 64bit: x0-x30 32bit: r0-r30 x0-x7: 用作传参 x8: 又被称为XR,用作返回值 x30: Link Register 4. 特殊寄存器 pc: 总是保存当前指令的地址,不可写 wzr/xzr: 32位和64位零寄存器 5. svc指令(Supervisor Call) 用作EL0 -> EL1 6. aarch64系统调用table linux/include/uapi/asm-generic/unistd.h 7. 指令: mov: 数据复制指令(example 1) ldr: 内存访问指令 (example 2) .req: 伪指令,别称 .macro: 自定义宏,相当于函数 (example 3) b: 无条件跳转指令, 跳转后无法回到原来位置继续执行下一指令 (example 4) bl: 跳转指令,保存下一条指令地址到LR寄存器(x30),指令执行完成后使用LR的地址继续往下执行 (example 4) ret: 返回指令,通常配合bl使用,默认使用LR寄存器,返回到LR保存的地址执行函数 (example 4) .space: 分配内存 (example 5) adr: 计算PC相对偏移处的地址 (example 5) adrp: 计算PC + imm相对偏移出page的地址 (example 5) str: 将源寄存器的数据存储到存储器地址中 str x0, [x1] // 将x0的值存到x1中 str x0, [x1], #8 // 将x0的值存到x1中,之后x1偏移到x1+8 str x0, [x1, #8] // 将x0的值存到x1+8中