Jump to content
Sign in to follow this  
chuckj

How Do I Call A C Procedure With A Param From Assembly?

Recommended Posts

My apologies if this has been asked before!

 

I have a C routine:

void CalcCRC( unsigned char ucData )
{
}

that I would like to call from inline assembly.

 

I found that calling the routine can be done by:

asm
{
  //This compiles fine in assembly without a leading underscore.
  call CalcCRC
}

 

My problem is how to access the parameter ucData to the CalcCRC procedure from inline assembly.

I have tried:

   movwf  ucData
  movwf  _ucData
  movwf  CalcCRC_ucData
  movwf  _CalcCRC_ucData
  movwf  CalcCRC_arg_ucData
  movwf  _CalcCRC_arg_ucData

 

I know I can declare ucData as a global and have no params on the CalcCRC procedure.

Is there a way to do this having ucData as a parameter?

 

Thanks!

Share this post


Link to post
Share on other sites
My apologies if this has been asked before!

 

I have a C routine:

void CalcCRC( unsigned char ucData )
{
}

that I would like to call from inline assembly.

 

I found that calling the routine can be done by:

asm
{
  //This compiles fine in assembly without a leading underscore.
  call CalcCRC
}

 

My problem is how to access the parameter ucData to the CalcCRC procedure from inline assembly.

I have tried:

   movwf  ucData
  movwf  _ucData
  movwf  CalcCRC_ucData
  movwf  _CalcCRC_ucData
  movwf  CalcCRC_arg_ucData
  movwf  _CalcCRC_arg_ucData

 

I know I can declare ucData as a global and have no params on the CalcCRC procedure.

Is there a way to do this having ucData as a parameter?

 

Thanks!

 

You need to declare ucData global. Linker allocates space for function arguments and these locations are not known at compile time.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
My apologies if this has been asked before!

 

I have a C routine:

void CalcCRC( unsigned char ucData )
{
}

that I would like to call from inline assembly.

 

I found that calling the routine can be done by:

asm
{
  //This compiles fine in assembly without a leading underscore.
  call CalcCRC
}

 

My problem is how to access the parameter ucData to the CalcCRC procedure from inline assembly.

I have tried:

   movwf  ucData
  movwf  _ucData
  movwf  CalcCRC_ucData
  movwf  _CalcCRC_ucData
  movwf  CalcCRC_arg_ucData
  movwf  _CalcCRC_arg_ucData

 

I know I can declare ucData as a global and have no params on the CalcCRC procedure.

Is there a way to do this having ucData as a parameter?

 

Thanks!

 

 

This may not be helpful, but can you do the call from a C subroutine in the usual way, but imbed asm for most of your code? This might give you the advantages of asm, but let the normal C calls be used.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...