calling a c funtion from assembly having two arguments.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

calling a c funtion from assembly having two arguments.

Jump to solution
1,433 Views
luck
Contributor III

i  have a c function for eg :  void function_name(char param1,char param2)

 

now i want to call this function from assembly code.

 

i know that how to call a c funtion with one parameter from assembly

 

eg:  ldab #12    

      jsr function_name

 

but i dont know how to pass two parameters from assembly while calling a c function.

 

i am using microcontroller MC9S12XDT512

 

and i am using freescale code warrior.

 

so please suggest if any body know how to do it.

Labels (1)
1 Solution
1,237 Views
kef
Specialist I

void function_name(char param1,char param2);

try this

    LDAB   <param1_value>

    PSHB

    LDAB   <param2_value>

    JSR    function_name   ;  (JSR or CALL depends on memory model)

    LEAS   1,SP  ; remove param1 from stack

View solution in original post

4 Replies
1,237 Views
CrasyCat
Specialist III

Hello

If you wish to call a function implemented in assembler from an ANSI C function, you need to match the C compiler calling convention in your assembler function.

If you are using the CodeWarrior compiler, the calling convention and parameter passing scheme is described in the file Compiler_HC12.pdf, chapter Using the Compiler, section HC(S)12 Backend > Call Protocol and Calling Conventions.

I hope this helps.

CrasyCat

1,237 Views
luck
Contributor III

thanks crasy for the reply

i looked into the pdf you mentioned above and yes there is topic about Call Protocol and Calling Conventions. but i m still not able to apply it .

if possible could you provide me some examples of calling a c function from assembly which has two parameters or more.

thanks

0 Kudos
Reply
1,238 Views
kef
Specialist I

void function_name(char param1,char param2);

try this

    LDAB   <param1_value>

    PSHB

    LDAB   <param2_value>

    JSR    function_name   ;  (JSR or CALL depends on memory model)

    LEAS   1,SP  ; remove param1 from stack

1,237 Views
luck
Contributor III

Hi Edward .

i tried it and its working fine.

thanks for the help thanks a lot

0 Kudos
Reply