functional essence
SP and FP registers
- The sp register will hold the address of the top of our stack at any time.
- The fp register, also known as the x29 register, is a general-purpose register, but at some point we use it to save the address at the bottom of the stack! ()
Note: Starting from ARM64, the 32-bit LDM, STM, PUSH, POP instructions are cancelled! Instead, ldr\ldp str\stp
The stack operation in ARM64 is 16-byte aligned!!
About memory read and write instructions
Note: read/write data is to read/write to high address
str(store register) instruction
Read the data from the register and store it in the memory.
ldr(load register) instruction
Read data from memory and store in register
The variants ldp and stp of this ldr and str can also operate on 2 registers.
stack manipulation exercise
Use 32 bytes of space as the stack space for this program, and then use the stack to exchange the values of x0 and x1.
sub sp, sp, #0x20 ;拉伸栈空间32个字节
stp x0, x1, [sp, #0x10] ;sp往上加16个字节,存放x0 和 x1
ldp x1, x0, [sp, #0x10] ;将sp偏移16个字节的值取出来,放入x1 和 x0
bl and ret instructions
bl label
- Put the address of the next instruction into the lr(x30) register
- Go to the label to execute the instruction
right
- By default, the value of the lr(x30) register is used, and the underlying instruction prompts the CPU to use this as the next instruction address!
The characteristic instructions of the ARM64 platform, which are optimized for hardware
x30 register
The x30 register stores the return address of the function. When the ret instruction is executed, it will look for the address value stored in the x30 register!
Note: When the function is nested and called. You need to talk about x30 into the stack!
Function parameters and return value
Under ARM64, the parameters of the function are stored in the 8 registers X0 to X7 (W0 to W7). If there are more than 8 parameters, they will be pushed onto the stack.
The return value of the function is placed in the X0 register.
function local variables
The local variables of the function are placed on the stack!