calling a c funtion from assembly having two arguments.

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

calling a c funtion from assembly having two arguments.

ソリューションへジャンプ
1,059件の閲覧回数
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.

ラベル(1)
1 解決策
863件の閲覧回数
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

元の投稿で解決策を見る

4 返答(返信)
863件の閲覧回数
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

863件の閲覧回数
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 件の賞賛
864件の閲覧回数
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

863件の閲覧回数
luck
Contributor III

Hi Edward .

i tried it and its working fine.

thanks for the help thanks a lot

0 件の賞賛