#include <stdint.h> uint32_t arg = 0x12345678; uint32_t getArgVal0( uint32_t * arg) { return *arg; } uint32_t getArgVal( uint32_t arg) { return getArgVal0( &arg ); } uint32_t * getArgPtr( uint32_t arg) { return &arg; } int main( void ) { arg = (uint32_t)getArgVal( arg); // OK arg = (uint32_t)getArgPtr( arg); // ERROR }
getArgVal0: 0x200050d0: 0x6800 LDR R0, [R0] 0x200050d2: 0x4770 BX LR getArgVal: 0x200050d4: 0xb501 PUSH {R0, LR} 0x200050d6: 0xa800 ADD R0, SP, #0x0 ; Push Arg to Stack, use Address of Stack as argument pass to getArgVal0() 0x200050d8: 0xf7ff 0xfffa BL getArgVal0 ; 0x200050d0 0x200050dc: 0xbd02 POP {R1, PC} getArgPtr: 0x200050de: 0xb401 PUSH {R0} 0x200050e0: 0xa800 ADD R0, SP, #0x0 ; Push Arg to Stack, Return Address of Stack 0x200050e2: 0xb001 ADD SP, SP, #0x4 0x200050e4: 0x4770 BX LR main: 0x200050e8: 0x481b LDR.N R0, ??DataTable1_1 ; arg 0x200050ea: 0x6800 LDR R0, [R0] 0x200050ec: 0xf7ff 0xfff2 BL getArgVal ; 0x200050d4 0x200050f0: 0x4919 LDR.N R1, ??DataTable1_1 ; arg 0x200050f2: 0x6008 STR R0, [R1] 0x200050f4: 0x4818 LDR.N R0, ??DataTable1_1 ; arg 0x200050f6: 0x6800 LDR R0, [R0] 0x200050f8: 0xf7ff 0xfff1 BL getArgPtr ; 0x200050de 0x200050fc: 0x4916 LDR.N R1, ??DataTable1_1 ; arg 0x200050fe: 0x6008 STR R0, [R1] ; R0 is Address in Stack, NOT global
使用通过寄存器传递的参数的地址, 作为支持调用其他函数
时间: 2024-11-06 16:56:07