1 说明
实验平台: JZ2440
CPU: S3C2440
2 ARM-THUMB Procedure Call Standard(ATPCS: ARM-Thumb过程调用标准)
图1 ATPCS中各寄存器的使用规则和名称
2.1 数据栈结构
我们使用的栈结构为FD(Full Descending)类型。注意:栈基址所指向的内存单元,不存放数据。
图2 栈结构
2.2 参数传递规则
根据参数个数是否固定,可以将子程序分为参数个数固定的子程序和参数个数可变的的子程序。
2.2.1 参数个数可变的子程序传递规则
参数传递时,可以将所有参数看作是存放在连续的存储字单元中的字数据。
当参数个数不超过4个时,使用寄存器R0-R3来传递参数,依次将各个字数据分别传送到寄存器R0-R3中去。
当参数个数超过4个时,还需使用数据栈来传递参数,把前4个字数据分别传送到寄存器R0-R3中去,剩余的字数据传送到数据栈中,需要注意的是,入栈顺序与参数顺序相反,即最后一个字数据先入栈。
2.2.2 参数个数固定的子程序传递规则
第一个整数参数通过寄存器R0-R3来传递,其他参数通过数据栈传递。
2.2.3 子程序结果返回规则
结果为一个32位的整数时,可以通过寄存器R0来返回。
结果为一个64位的整数时,可以通过寄存器R0和R1来返回,以此类推。
对于位数更多的结果,需要通过内存来反回。
3 反汇编代码分析
附录1:源码
Start.S
main.c
相关文章









