<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Invoking Assembly implementation from c file in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Invoking-Assembly-implementation-from-c-file/m-p/568918#M17814</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Pacman on Tue Mar 11 05:54:56 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;You're using gcc and gas, right ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You might need to add the directive [color=#060]&lt;/SPAN&gt;&lt;STRONG&gt;.thumb_func&lt;/STRONG&gt;&lt;SPAN&gt;[/color] for this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that thumb code has the 'odd' bit set; eg. the least signficant bit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Instructions are always placed on even addresses, eg. the least significant bit is cleared.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thus if you place a label right before the first instruction in a subroutine, this label will usually have its least significant bit cleared.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So when you branch to the subroutine, the compiler / assembler needs to know that this label points to thumb code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[color=#060]&lt;/SPAN&gt;&lt;STRONG&gt;.thumb_func&lt;/STRONG&gt;&lt;SPAN&gt;[/color] should do just that; but it might not be enough, in case you use tables for storing function pointers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If that's the case, you might need a [color=#060]&lt;/SPAN&gt;&lt;STRONG&gt;.type&lt;/STRONG&gt;&lt;SPAN&gt;[/color] directive as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;.text
.syntaxunified

.globalmySubroutine
.funcmySubroutine
.thumb_func
.typemySubroutine,%function
mySubroutine:
movsr0,#123
bxlr
.sizemySubroutine, . - mySubroutine
.endfunc&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I recommend that you make yourself a macro, that handles setting up a function for convenience.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's a simple one:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;.macroFUNCTION name:req
.global\name
.func\name
.thumb_func
.type\name,%function
\name\():
.endm

.macroENDFUNCname:req
.size\name, . - \name
.endfunc
.endm&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Eg.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
FUNCTIONmySubroutine
movsr0,#123
bxlr
ENDFUNCmySubroutine
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 18:52:12 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T18:52:12Z</dc:date>
    <item>
      <title>Invoking Assembly implementation from c file</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Invoking-Assembly-implementation-from-c-file/m-p/568917#M17813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by praveen.9123 on Fri Feb 28 04:38:55 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am facing an issue on LPC4330 board and have described the same below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am calling assembly implementation from c code where the hardware is going into hang state and am not seeing any further execution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have attached the assembly file for your reference.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do i need to add any flags to integrate assembly code with c code? Please help me. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Praveen&lt;/SPAN&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-338103"&gt;asmmisc_s.odt&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:52:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Invoking-Assembly-implementation-from-c-file/m-p/568917#M17813</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T18:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Invoking Assembly implementation from c file</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Invoking-Assembly-implementation-from-c-file/m-p/568918#M17814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Pacman on Tue Mar 11 05:54:56 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;You're using gcc and gas, right ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You might need to add the directive [color=#060]&lt;/SPAN&gt;&lt;STRONG&gt;.thumb_func&lt;/STRONG&gt;&lt;SPAN&gt;[/color] for this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that thumb code has the 'odd' bit set; eg. the least signficant bit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Instructions are always placed on even addresses, eg. the least significant bit is cleared.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thus if you place a label right before the first instruction in a subroutine, this label will usually have its least significant bit cleared.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So when you branch to the subroutine, the compiler / assembler needs to know that this label points to thumb code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[color=#060]&lt;/SPAN&gt;&lt;STRONG&gt;.thumb_func&lt;/STRONG&gt;&lt;SPAN&gt;[/color] should do just that; but it might not be enough, in case you use tables for storing function pointers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If that's the case, you might need a [color=#060]&lt;/SPAN&gt;&lt;STRONG&gt;.type&lt;/STRONG&gt;&lt;SPAN&gt;[/color] directive as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;.text
.syntaxunified

.globalmySubroutine
.funcmySubroutine
.thumb_func
.typemySubroutine,%function
mySubroutine:
movsr0,#123
bxlr
.sizemySubroutine, . - mySubroutine
.endfunc&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I recommend that you make yourself a macro, that handles setting up a function for convenience.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's a simple one:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;.macroFUNCTION name:req
.global\name
.func\name
.thumb_func
.type\name,%function
\name\():
.endm

.macroENDFUNCname:req
.size\name, . - \name
.endfunc
.endm&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Eg.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
FUNCTIONmySubroutine
movsr0,#123
bxlr
ENDFUNCmySubroutine
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:52:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Invoking-Assembly-implementation-from-c-file/m-p/568918#M17814</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T18:52:12Z</dc:date>
    </item>
  </channel>
</rss>

