Reputation: 41
Actually, I'm using NASM for my scholar project. The idea is to build one static library for Math Operations.
I've been able to build separate functions in different asm files. Example:
add_vectorial
sub_vectorial
But I have an third asm file that it must call the 2 functions: add_vectorial and sub_vectorial for to do some calculus.
I've read that i must to use the call word for calling my external function. But I don't have idea how can i pass the parameter??
Example of my code:
extern add_vectorial
global operation: ;for linux
operation:
;Initialize a stack frame
push ebp
mov ebp, esp
;Loading the arguments values
mov ebx, [ebp+8] ; ebx='d'
mov ecx, [ebp+12] ; ecx='v1'
mov edx, [ebp+16] ; edx='v2'
mov eax, [ebp+20] ; eax = rt
;Initial the xmm4 registry with zero.
xorps xmm4, xmm4
.body:
;Here, How can i pass the parameters to my asm external function?
call add_vectorial
.done:
;Restore the call's stack frame pointer
leave ; mov esp,ebp / pop ebp
ret ; return from function
Upvotes: 2
Views: 6166
Reputation: 41
Thanks guys for your support... Finally I found a one solution to my problem... I leave my solution..
%macro call_fun1 4
pushad ;I put this
push %4
push %3
push %2
push %1
call sub_vectorial
add esp, 16 ;4p*4bytes
popad ;I put this
%endmacro
Upvotes: 2
Reputation: 41
I've created a macro for calling my external functions, passing the parameter like in C.
%macro call_fun1 4
push %4
push %3
push %2
push %1
call sub_vectorial
add ebp, 16 ;4p*4bytes
%endmacro
Only when i integrate this code with my main asm file, give me the follow error: Program received signal SIGSEGV, Segmentation fault.
For this reason i made one unit test of my function, but the function work fine.
The error only is to give when i integrate with the rest of my code.
Upvotes: 0
Reputation: 2624
You can either pass the parameters by pushing them onto the stack before you execute the call statement, or by inserting them into registers first.
Upvotes: 0