title ccall
.386
.model flat,c
.data?
arg_num dword 0
arg_tab dword 100 dup(0)
arg_tye dword 100 dup(0)
fun_ptr dword 0
.code
push_arg_ini proc
mov arg_num, 0
ret
push_arg_ini endp
push_arg proc, arg : sdword, tye : sdword
mov eax, arg_num
mov ebx, offset arg_tab
mov ecx, arg
mov [ebx+eax*4], ecx
mov ebx, offset arg_tye
mov ecx, tye
mov [ebx+eax*4], ecx
add eax, 1
mov arg_num, eax
ret
push_arg endp
push_fun proc, fun : sdword
mov eax,fun
mov fun_ptr, eax
ret
push_fun endp
i_fun_call proc
local count : dword
xor eax, eax
mov ebx, offset arg_tab
mov ecx, offset arg_tye
mov count, 0
.while eax < arg_num
mov edx, [ecx+eax*4]
;浮点型入栈;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.if edx
fld dword ptr [ebx+eax*4]
sub esp,8
fstp qword ptr [esp]
.elseif
push [ebx+eax*4]
.endif
add eax, 1
add count, 4
.endw
mov eax, fun_ptr
call eax
add esp, count
ret
i_fun_call endp
f_fun_call proc
local count : dword
xor eax, eax
mov ebx, offset arg_tab
mov ecx, offset arg_tye
mov count, 0
.while eax < arg_num
mov edx, [ecx+eax*4]
;浮点型入栈;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.if edx
fld dword ptr [ebx+eax*4]
sub esp,8
fstp qword ptr [esp]
.elseif
push [ebx+eax*4]
.endif
add eax, 1
add count, 4
.endw
mov eax, fun_ptr
call eax
add esp, count
ret
f_fun_call endp
end