1. Arm64 profile
There are 31 general register and 2 special register in ARM64 system. The 31 general purpose registers are denoted by X0 to X30, and the two special registers are SP and ZR. SP is the stack pointer, its content is the address at the bottom of the stack, must meet the condition of 16-byte alignment, otherwise cannot be used. ZR is the zero register. When used as a source register, the value is always zero, and when used as a destination register, no value is saved.
B stands for byte, H stands for half byte, S stands for single word, D stands for double word, and Q stands for four word. The system register usually has a suffix _ELx: indicates the lowest exception level that can access the register, and there should be read (MRS) and write (MSR) instructions to the system register, respectively.
There are 34 registers in the ARM64, among which the X0-X30 general purpose register.
2. Arm64 registers
X0-x30 are 31 general purpose integer registers. Each register can access a 64 bit book, which is 64 bits when accessed using x0-X30. When w0-W30 access is used, the lower 32 bits of these registers are accessed.
FP (X29) saves the stack frame address LR (X30) is usually called the link register, saves the jump and place information address SP saves the stack pointer PC program counter. X0-x7 is used for parameter passing when a subroutine is called, and X0 is used for return value passing. X8: Indirection result LR: Saves the next instruction to be executed after the subroutine ends. CPSR: status register
3. Common ARM64 assembler instructions.
Mov x1,x0: transfer the value of register x0 to register x1 Add x0,x1, X2: transfer the value of register x1 and X2 to register x0 sub x0,x1, X2: transfer the value of register x1 and X2 to register x0 and x0,x0,#0xF: ORR X0, X0,# 9: X0 value with phase 9 or after value transmitted to X0 EOR X0, X0,# 0xF: X0 value with phase 9 or after value transmitted to X0 LDR x5, [x6,#0x08]; [sp,#0x8]: the data in the x0 register is transferred to the storage space pointed to by the sp+0x8 address value. LDP x29, x30,[sp,#0x10]: out of stack instruction CBZ: Comparison instruction, if the result is zero, transfer CBNZ: comparison, if the result is non-zero, transfer CMP: comparison instruction, CPSR B/BL: absolute jump, return address saved to LR(x30) RET: subroutine return instruction, return address saved to LR(x30) by default
The stack is the memory space in which temporary variables are stored. Lifo FP points to the bottom of the stack and SP points to the top.
SUB SP, SP, #0x10 ; Assign stack control 16 bytes; STR W0, [SP,#0x10+var_4] ; A LDR W0, [SP,#0x10+var_4]; W0 ADD SP, SP, #0x10; Flat stack, using the flat stack mode is ADD
4. Arm64 instruction introduction
ADR: a small range of address reading instructions. The ADR reads the address value into the register based on the relative offset of the PC. How it works: A signed 21-bit offset is added to the PC and the result is written to a general-purpose register that can be used to calculate the valid address of any byte in the +/-1MB range. ADRP: An instruction to read a wide range of addresses in pages, where P stands for page. Generally speaking, ADRP instruction is to first PC+ IMM (offset) and then find a 4KB page where the label is located, and then get the base address of the label, and then offset to address.
LDRSW x9, [x8, x9, LSS #2] to add the value of x9 register to the base address of X8 register and take the value of its address to x9 register.
If the so library file is a 64-bit program and the code in the program is 32-bit, then use the general register: W0-W30