x86 ASM - Parameter Problems

The answer is correct but I'm just wondering why I have to use [ebp+8] and [ebp+12].

Edit:
[ebp+0] stores the caller's base pointer
[ebp+4] stores the return address
[ebp+8] stores the first param

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using std::cout; using std::cin;

extern "C"
{
	int Sum(const int a, const int b);
}

int main()
{
	cout << Sum(1337, 7331) << "\n";

	cout << "\n" "Press enter to continue . . ." "\n";
	cin.get();
}


ASM.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.386
.model flat, C

.data

.code
Sum proc
	push ebp
	mov ebp, esp

	; why isn't the first param at [ebp+4] and 
	; the second at [ebp+8]?
	mov eax, [ebp+8]	; first param
	add eax, [ebp+12]	; second param

	mov esp, ebp
	pop ebp

	ret
Sum endp
end 
Last edited on
Topic archived. No new replies allowed.