Invoking Assembly implementation from c file

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

Invoking Assembly implementation from c file

385 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by praveen.9123 on Fri Feb 28 04:38:55 MST 2014
Hi,

I am facing an issue on LPC4330 board and have described the same below.

I am calling assembly implementation from c code where the hardware is going into hang state and am not seeing any further execution.
In detail, there is a function MULSHIFT32 is defined in .s file. I am calling MULSHIFT32 from a .c file where the issue is occurring.

I have attached the assembly file for your reference.

Do i need to add any flags to integrate assembly code with c code? Please help me.

Regards,
Praveen

Original Attachment has been moved to: asmmisc_s.odt

Labels (1)
0 Kudos
1 Reply

336 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Pacman on Tue Mar 11 05:54:56 MST 2014
You're using gcc and gas, right ?

You might need to add the directive [color=#060].thumb_func[/color] for this.
The problem is that thumb code has the 'odd' bit set; eg. the least signficant bit.
Instructions are always placed on even addresses, eg. the least significant bit is cleared.
Thus if you place a label right before the first instruction in a subroutine, this label will usually have its least significant bit cleared.
So when you branch to the subroutine, the compiler / assembler needs to know that this label points to thumb code.
[color=#060].thumb_func[/color] should do just that; but it might not be enough, in case you use tables for storing function pointers.
If that's the case, you might need a [color=#060].type[/color] directive as well.

Example:
.text
.syntaxunified

.globalmySubroutine
.funcmySubroutine
.thumb_func
.typemySubroutine,%function
mySubroutine:
movsr0,#123
bxlr
.sizemySubroutine, . - mySubroutine
.endfunc


I recommend that you make yourself a macro, that handles setting up a function for convenience.

Here's a simple one:
.macroFUNCTION name:req
.global\name
.func\name
.thumb_func
.type\name,%function
\name\():
.endm

.macroENDFUNCname:req
.size\name, . - \name
.endfunc
.endm


You must provide the name of the subroutine to both FUNCTION and ENDFUNC; the label is set up by FUNCTION, so you do not need to add the label anywhere yourself.
Eg.
FUNCTIONmySubroutine
movsr0,#123
bxlr
ENDFUNCmySubroutine

0 Kudos