Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#define multi_max(a,b,c) (c)=(a>b)?(a):(b)
int __fastcall multiparam_fastcall(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j,int k,int l,int m) {
    
    int tmp1=(a>b)?a:b;
    multi_max(tmp1,c,tmp1);
    multi_max(tmp1,d,tmp1);
    multi_max(tmp1,e,tmp1);
    multi_max(tmp1,f,tmp1);
    multi_max(tmp1,g,tmp1);
    multi_max(tmp1,h,tmp1);
    multi_max(tmp1,i,tmp1);
    multi_max(tmp1,j,tmp1);
    multi_max(tmp1,k,tmp1);
    multi_max(tmp1,l,tmp1);
    multi_max(tmp1,m,tmp1);
    
    return tmp1;
}


; Function compile flags: /Odtp
; File e:\src_ref\test\caller_callee\stack_param.c
_TEXT	SEGMENT
tmp1$ = 0
tv65 = 4
tv67 = 8
tv69 = 12
tv71 = 16
tv73 = 20
tv75 = 24
tv77 = 28
tv79 = 32
tv81 = 36
tv83 = 40
tv85 = 44
tv87 = 48
a$ = 80
b$ = 88
c$ = 96
d$ = 104
e$ = 112
f$ = 120
g$ = 128
h$ = 136
i$ = 144
j$ = 152
k$ = 160
l$ = 168
m$ = 176
multiparam_fastcall PROC

; 71   : int __fastcall multiparam_fastcall(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j,int k,int l,int m/*,int n*/) {

$LN27:
	mov	DWORD PTR [rsp+32], r9d
	mov	DWORD PTR [rsp+24], r8d
	mov	DWORD PTR [rsp+16], edx
	mov	DWORD PTR [rsp+8], ecx
	sub	rsp, 72					; 00000048H

; 72   :     
; 73   :     int tmp1=(a>b)?a:b;

	mov	eax, DWORD PTR b$[rsp]
	cmp	DWORD PTR a$[rsp], eax
	jle	SHORT $LN3@multiparam
	mov	eax, DWORD PTR a$[rsp]
	mov	DWORD PTR tv65[rsp], eax
	jmp	SHORT $LN4@multiparam
$LN3@multiparam:
	mov	eax, DWORD PTR b$[rsp]
	mov	DWORD PTR tv65[rsp], eax
$LN4@multiparam:
	mov	eax, DWORD PTR tv65[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 74   :     multi_max(tmp1,c,tmp1);

	mov	eax, DWORD PTR c$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN5@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv67[rsp], eax
	jmp	SHORT $LN6@multiparam
$LN5@multiparam:
	mov	eax, DWORD PTR c$[rsp]
	mov	DWORD PTR tv67[rsp], eax
$LN6@multiparam:
	mov	eax, DWORD PTR tv67[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 75   :     multi_max(tmp1,d,tmp1);

	mov	eax, DWORD PTR d$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN7@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv69[rsp], eax
	jmp	SHORT $LN8@multiparam
$LN7@multiparam:
	mov	eax, DWORD PTR d$[rsp]
	mov	DWORD PTR tv69[rsp], eax
$LN8@multiparam:
	mov	eax, DWORD PTR tv69[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 76   :     multi_max(tmp1,e,tmp1);

	mov	eax, DWORD PTR e$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN9@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv71[rsp], eax
	jmp	SHORT $LN10@multiparam
$LN9@multiparam:
	mov	eax, DWORD PTR e$[rsp]
	mov	DWORD PTR tv71[rsp], eax
$LN10@multiparam:
	mov	eax, DWORD PTR tv71[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 77   :     multi_max(tmp1,f,tmp1);

	mov	eax, DWORD PTR f$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN11@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv73[rsp], eax
	jmp	SHORT $LN12@multiparam
$LN11@multiparam:
	mov	eax, DWORD PTR f$[rsp]
	mov	DWORD PTR tv73[rsp], eax
$LN12@multiparam:
	mov	eax, DWORD PTR tv73[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 78   :     multi_max(tmp1,g,tmp1);

	mov	eax, DWORD PTR g$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN13@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv75[rsp], eax
	jmp	SHORT $LN14@multiparam
$LN13@multiparam:
	mov	eax, DWORD PTR g$[rsp]
	mov	DWORD PTR tv75[rsp], eax
$LN14@multiparam:
	mov	eax, DWORD PTR tv75[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 79   :     multi_max(tmp1,h,tmp1);

	mov	eax, DWORD PTR h$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN15@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv77[rsp], eax
	jmp	SHORT $LN16@multiparam
$LN15@multiparam:
	mov	eax, DWORD PTR h$[rsp]
	mov	DWORD PTR tv77[rsp], eax
$LN16@multiparam:
	mov	eax, DWORD PTR tv77[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 80   :     multi_max(tmp1,i,tmp1);

	mov	eax, DWORD PTR i$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN17@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv79[rsp], eax
	jmp	SHORT $LN18@multiparam
$LN17@multiparam:
	mov	eax, DWORD PTR i$[rsp]
	mov	DWORD PTR tv79[rsp], eax
$LN18@multiparam:
	mov	eax, DWORD PTR tv79[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 81   :     multi_max(tmp1,j,tmp1);

	mov	eax, DWORD PTR j$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN19@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv81[rsp], eax
	jmp	SHORT $LN20@multiparam
$LN19@multiparam:
	mov	eax, DWORD PTR j$[rsp]
	mov	DWORD PTR tv81[rsp], eax
$LN20@multiparam:
	mov	eax, DWORD PTR tv81[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 82   :     multi_max(tmp1,k,tmp1);

	mov	eax, DWORD PTR k$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN21@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv83[rsp], eax
	jmp	SHORT $LN22@multiparam
$LN21@multiparam:
	mov	eax, DWORD PTR k$[rsp]
	mov	DWORD PTR tv83[rsp], eax
$LN22@multiparam:
	mov	eax, DWORD PTR tv83[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 83   :     multi_max(tmp1,l,tmp1);

	mov	eax, DWORD PTR l$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN23@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv85[rsp], eax
	jmp	SHORT $LN24@multiparam
$LN23@multiparam:
	mov	eax, DWORD PTR l$[rsp]
	mov	DWORD PTR tv85[rsp], eax
$LN24@multiparam:
	mov	eax, DWORD PTR tv85[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 84   :     multi_max(tmp1,m,tmp1);

	mov	eax, DWORD PTR m$[rsp]
	cmp	DWORD PTR tmp1$[rsp], eax
	jle	SHORT $LN25@multiparam
	mov	eax, DWORD PTR tmp1$[rsp]
	mov	DWORD PTR tv87[rsp], eax
	jmp	SHORT $LN26@multiparam
$LN25@multiparam:
	mov	eax, DWORD PTR m$[rsp]
	mov	DWORD PTR tv87[rsp], eax
$LN26@multiparam:
	mov	eax, DWORD PTR tv87[rsp]
	mov	DWORD PTR tmp1$[rsp], eax

; 85   :     //multi_max(tmp1,n,tmp1);
; 86   :     
; 87   :     return tmp1;

	mov	eax, DWORD PTR tmp1$[rsp]

; 88   : }

	add	rsp, 72					; 00000048H
	ret	0
multiparam_fastcall ENDP
_TEXT	ENDS


What I have tried:

sub rsp,72
...
add rsp,72

how did the size 72 calculated ?
Posted
Comments
Shao Voon Wong 30-Sep-22 21:42pm    
You have 14 4-bytes parameters. 4 of those are passed in 64-bit registers. The rest are passed in 32-bit storage on stack. There is no __fastcall convention in x64. All functions use the same calling convention in x64.

((14 - 4) * 4bytes) + (4 * 8bytes) = 40 + 32 = 72

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900