- 打卡等级:初来乍到
- 打卡总天数:7
- 最近打卡:2025-04-01 23:18:33
高级会员
- 积分
- 977
|
发表于 2024-6-25 23:05:27
|
显示全部楼层
参考keil c51帮助文件 “Passing in Registers” 一节
C functions may pass parameters in registers and fixed memory locations. A maximum of 3 parameters may be passed in registers. All other parameters are passed using fixed memory locations. The following tables define which registers are used for passing parameters.
Arg Number char,
1-byte ptr int,
2-byte ptr long, float generic ptr
1 R7 R6 & R7
(MSB in R6,LSB in R7) R4—R7 R1—R3
(Mem type in R3, MSB in R2, LSB in R1)
2 R5 R4 & R5
(MSB in R4,LSB in R5) R4—R7 R1—R3
(Mem type in R3, MSB in R2, LSB in R1)
3 R3 R2 & R3
(MSB in R2,LSB in R3) R1—R3
(Mem type in R3, MSB in R2, LSB in R1)
The following examples clarify how registers are selected for parameter passing.
Declaration Description
func1 (
int a) The first and only argument, a, is passed in registers R6 and R7.
func2 (
int b,
int c,
int *d) The first argument, b, is passed in registers R6 and R7. The second argument, c, is passed in registers R4 and R5. The third argument, d, is passed in registers R1, R2, and R3.
func3 (
long e,
long f) The first argument, e, is passed in registers R4, R5, R6, and R7. The second argument, f, cannot be located in registers since those available for a second parameter with a type of long are already used by the first argument. This parameter is passed using fixed memory locations.
func4 (
float g,
char h) The first argument, g, passed in registers R4, R5, R6, and R7. The second parameter, h, cannot be passed in registers and is passed in fixed memory locations.
|
|