But the two asm listing above correspond to cases which work!
Now below, for asm specialists:
- one case which works:
function pass_byval_ptr cdecl(byval p as integer ptr) as integer
- one case which does not work:
function pass_naked_byval_ptr naked cdecl(byval p as integer ptr) as integer
Together compiled with option '-exx'.
Code: Select all
function pass_byval_ptr cdecl(byval p as integer ptr) as integer
asm
mov eax, [p]
mov eax, [eax]
mov [function], eax
end asm
end function
dim test as integer = 1234
print pass_byval_ptr(@test)
Code: Select all
.globl _PASS_BYVAL_PTR
_PASS_BYVAL_PTR:
push ebp
mov ebp, esp
sub esp, 12
push ebx
push esi
push edi
mov dword ptr [ebp-4], 0
push offset _Lt_0007
call _fb_ErrorSetModName@4
mov dword ptr [ebp-8], eax
push offset _Lt_0009
call _fb_ErrorSetFuncName@4
mov dword ptr [ebp-12], eax
.Lt_0004:
mov eax, [ebp+8]
mov eax, [eax]
mov [ebp-4], eax
.Lt_0005:
push dword ptr [ebp-12]
call _fb_ErrorSetFuncName@4
push dword ptr [ebp-8]
call _fb_ErrorSetModName@4
mov eax, dword ptr [ebp-4]
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
.balign 16
_fb_ctor__FBIDETEMP:
push ebp
mov ebp, esp
sub esp, 12
.Lt_0002:
push offset _Lt_000C
call _fb_ErrorSetModName@4
mov dword ptr [ebp-8], eax
push offset _Lt_000E
call _fb_ErrorSetFuncName@4
mov dword ptr [ebp-12], eax
mov dword ptr [ebp-4], 1234
push 1
lea eax, [ebp-4]
push eax
call _PASS_BYVAL_PTR
add esp, 4
push eax
push 0
call _fb_PrintInt@12
.Lt_0003:
push dword ptr [ebp-12]
call _fb_ErrorSetFuncName@4
push dword ptr [ebp-8]
call _fb_ErrorSetModName@4
mov esp, ebp
pop ebp
ret
Code: Select all
function pass_naked_byval_ptr naked cdecl(byval p as integer ptr) as integer
asm
mov eax, [esp+4]
mov eax, [eax]
ret
end asm
end function
dim test as integer = 1234
print pass_naked_byval_ptr(@test)
Code: Select all
.globl _PASS_NAKED_BYVAL_PTR
_PASS_NAKED_BYVAL_PTR:
.Lt_0004:
push offset _Lt_0007
call _fb_ErrorSetModName@4
mov dword ptr [ebp-4], eax
push offset _Lt_0009
call _fb_ErrorSetFuncName@4
mov dword ptr [ebp-8], eax
mov eax, [esp+4]
mov eax, [eax]
ret
.Lt_0005:
push dword ptr [ebp-8]
call _fb_ErrorSetFuncName@4
push dword ptr [ebp-4]
call _fb_ErrorSetModName@4
.balign 16
_fb_ctor__FBIDETEMP:
push ebp
mov ebp, esp
sub esp, 12
.Lt_0002:
push offset _Lt_000C
call _fb_ErrorSetModName@4
mov dword ptr [ebp-8], eax
push offset _Lt_000E
call _fb_ErrorSetFuncName@4
mov dword ptr [ebp-12], eax
mov dword ptr [ebp-4], 1234
push 1
lea eax, [ebp-4]
push eax
call _PASS_NAKED_BYVAL_PTR
add esp, 4
push eax
push 0
call _fb_PrintInt@12
.Lt_0003:
push dword ptr [ebp-12]
call _fb_ErrorSetFuncName@4
push dword ptr [ebp-8]
call _fb_ErrorSetModName@4
mov esp, ebp
pop ebp
ret
I think that:
call _fb_ErrorSetFuncName@4
mov dword ptr [ebp-8], eax
overwrites the value '1234'.
A last case which works:
function pass_naked_byval_ptr naked cdecl(byval p as integer ptr) as integer, as just above, but compiled without '-exx':
Code: Select all
.globl _PASS_NAKED_BYVAL_PTR
_PASS_NAKED_BYVAL_PTR:
.Lt_0004:
mov eax, [esp+4]
mov eax, [eax]
ret
.Lt_0005:
.balign 16
_fb_ctor__FBIDETEMP:
push ebp
mov ebp, esp
sub esp, 4
.Lt_0002:
mov dword ptr [ebp-4], 1234
push 1
lea eax, [ebp-4]
push eax
call _PASS_NAKED_BYVAL_PTR
add esp, 4
push eax
push 0
call _fb_PrintInt@12
.Lt_0003:
mov esp, ebp
pop ebp
ret