★★★个人博客导读首页—点击此处 ★★★
示例1:
int func_test(uint32_t a, uint32_t b, uint32_t *s) { *s = a + b; return 0; } 00000000002047a0 <func_test>: 2047a0: 0b010000 add w0, w0, w1 2047a4: b9000040 str w0, [x2] 2047a8: 52800000 mov w0, #0x0 // #0 2047ac: d65f03c0 ret
示例2
int func_memcpy(void *a, void *b, uint32_t len) { memcpy(a,b,len); return 0; } int func_test(uint32_t integer1, uint32_t integer2, uint32_t *p_integer) { char a[128]; *p_integer = integer1 + integer2; func_memcpy(a,"testtesttesttesttesttest",*p_integer); return 0; } 数据段中的:"testtesttesttesttesttest" 215430: 6f697372 7325206e 6574000a 65747473 rsion %s..testte 215440: 65747473 65747473 65747473 65747473 sttesttesttestte 215450: 76007473 69737265 25206e6f 64252c64 st.version %d,%d 00000000002047a0 <func_test>: 2047a0: a9b77bfd stp x29, x30, [sp,#-144]! 2047a4: 0b010000 add w0, w0, w1 2047a8: b0000081 adrp x1, 215000 <build_message+0x2a0> 2047ac: 910003fd mov x29, sp 2047b0: b9000040 str w0, [x2] 2047b4: 9110e821 add x1, x1, #0x43a 2047b8: 2a0003e2 mov w2, w0 2047bc: 910043a0 add x0, x29, #0x10 2047c0: 94003d7d bl 213db4 <memcpy> 2047c4: 52800000 mov w0, #0x0 // #0 2047c8: a8c97bfd ldp x29, x30, [sp],#144 2047cc: d65f03c0 ret
由此看来,这是一个递减的栈.
(1)
stp x29, x30, [sp,#-144]! //sp=sp-144后,将x29和x30拷贝到sp中,即:
0到-128是数组变量a,-129到-144是 x29和x30(lr)。 这里其实就是保存x29和x30
(2)
add x0, x29, #0x10 //x29是当前的栈地址(sp),sp+0x10正好就是数组a的地址,这句就是将数组a的地址拷贝到x0中
(3)ldp x29, x30, [sp],#144 从sp处拷贝两个double-world到x29和x30,这里其实就是恢复x29和x30。 拷贝之后,再sp=sp+144