Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stdcall asm floating point parameters

Tags:

x86

assembly

d

using D inline assembly im trying to implement calling stdcall functions dynamically (with dynamic parameters)

i have the following assembly args is a void pointer to an array of 32bit integers argc is the number of is the argument count ret is a void pointer and address is the function address

 MOV EBX, 0;
 iterator:
 MOV EAX, DWORD PTR [args];
 PUSH EAX;
 ADD EBX, 1;
 ADD EAX, 4;
 CMP EBX, DWORD PTR argc;
 JNE iterator;
 MOV EAX, ADDress;
 CALL EAX;
 MOV [ret], EAX;
 RET 0;

how are floating point arguments passed?

like image 866
Computermatronic Avatar asked Nov 01 '22 05:11

Computermatronic


1 Answers

Microsoft is very silent on this issue.
This is because stdcall is only used for WinAPI calls.
And no WinAPI call that I know of accepts floating point parameters.

According to all the documentation I can find all parameters are pushed onto the stack.
This includes floating point parameters.

If I compile the following snippet in my compiler it confirms this:

void __stdcall test3(double a, double b, double c) {
};     
.....
test3(a,b,c);
.....
//This produces the following code as per the stdcall convention. 
004182B4 55               push ebp
004182B5 8BEC             mov ebp,esp
004182B7 83C4E8           add esp,-$18
004182BA FF75EC           push dword ptr [ebp-$14]
004182BD FF75E8           push dword ptr [ebp-$18]
004182C0 FF75F4           push dword ptr [ebp-$0c]
004182C3 FF75F0           push dword ptr [ebp-$10]
004182C6 FF75FC           push dword ptr [ebp-$04]
004182C9 FF75F8           push dword ptr [ebp-$08]
004182CC E8ABFFFFFF       call Test3

Note that a floating point return value gets returned in ST(0).

like image 110
Johan Avatar answered Nov 15 '22 13:11

Johan