<?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: Call C functions from assembly language project in LPCXpresso IDE</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558620#M15098</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by TheFallGuy on Sun Feb 24 15:32:55 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: MikeSimmonds&lt;/STRONG&gt;&lt;BR /&gt;[FONT=Tahoma][SIZE=1]As promised, my number formatting code.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I object very strongly to the way that ARM (the company) abribtrarily overturned 50+ (well at least 40) years of&lt;BR /&gt;tradition and changed the comment character from ';' to '@' (ugly in quantity). They then suggest the we use&lt;BR /&gt;the hijacked ';' as a statement seperator. Is this an attempt to make assember resemble "C" -- a forlorn attempt!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is no standard comment character, it depends on the architecture. See&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://"&gt;http://en.wikipedia.org/wiki/GNU_Assembler&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To quote from the above page:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Single-Line comments:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Single line comments have a few different formats varying on which architecture is being assembled for.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hash symbols are used for the platforms: i386, x86-64, i960, 68HC11, 68HC12, VAX, V850, m32r, and M880x0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Semicolons are used on: AMD 29K family, ARC, H8/300 family, HPPA,PDP-11, picoJava, Motorola, and PowerPC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The at sign is used on the ARM platform.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A vertical bar is used to signify comments when assembling on 680x0.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 23:36:07 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T23:36:07Z</dc:date>
    <item>
      <title>Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558612#M15090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by cwpjr on Fri Feb 22 15:06:22 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Originally Posted by [B]TheFallGuy[/B]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://http://knowledgebase.nxp.com/showthread.php?p=21710#post21710"&gt;[IMG]http://knowledgebase.nxp.com/images/buttons/viewpost.gif[/IMG]&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [I]Thats irrelevant. You can call C functions from assembly language.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[/I]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; What if I don't use, or know C?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All the help I can find is about inline assembly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are there examples to learn from?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How would the smallest c call/ included lib overheard configuration be integrated into an existing assembly language project?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, Clyde&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558612#M15090</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558613#M15091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MikeSimmonds on Fri Feb 22 19:52:12 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;[FONT=Trebuchet MS][SIZE=1]Hi Clyde. Some hints, but not the full story (as that would take too long).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;First you [B]must[/B] read up on the ABI (Application Binary Interface). Search the ARM site.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But in a nutshell, a function is called with up to 4 parameters in registers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is true for asm calls "C" and also "C" calls asm.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;E.g. Func(a,b,c,d) will be called with r0=a, r1=b, r2=c, r3=d.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 'type' can be anything e.g. ptr to "C" string (null terminated) a number promoted to long&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;taking sign into account if reqd.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is the simple case, obviously you can have more than 4 arguements, but I won't cover that here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The return value (if any) goes into r0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any function either "C" or asm must preserve r4-r11 (and lr/sp/pc of course -- I take it you know about the lr&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and bx lr for single depth calls and pushing lr/popping pc when you function calls nested functions)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It can do whatever it likes with r0-r3 and also r12; bearing in mind the parameters/return rules stated above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need more than these, you must save and restore what you use.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A silly example (better done in asm anyway)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The "C"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;int SillyFunc(char *buffer, char startValue,&amp;nbsp; long length)
{
&amp;nbsp;&amp;nbsp; long tot = 0; 
&amp;nbsp; while (length--)
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *buffer++ = startValue;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tot = tot + startValue;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; startValue += 11;
&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; return(tot);
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;the asm calling it&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
...
&amp;nbsp;&amp;nbsp; ldr&amp;nbsp;&amp;nbsp; r0, =myBuffer
&amp;nbsp;&amp;nbsp; movs r1, 0x42
&amp;nbsp; ldr&amp;nbsp; r2, =1492
&amp;nbsp; bl SillyFunc
&amp;nbsp; ldr&amp;nbsp;&amp;nbsp; r1, =SomeVar
 str&amp;nbsp;&amp;nbsp; r0, [r1]
...
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;I personally [I]never[/I] use any "C" library functions and (if I were building via the IDE) select options for the "C" build&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;to disable all libraries (newLib, redLib, ...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually I build via an external make, the C flags from m makefile are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CCFLAGS&amp;nbsp;&amp;nbsp;&amp;nbsp; += -mcpu=cortex-m3 -mthumb -funsigned-char -g3 $(OPTIM)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CCFLAGS&amp;nbsp;&amp;nbsp;&amp;nbsp; += -nostartfiles -nodefaultlibs -nostdinc&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CCFLAGS&amp;nbsp;&amp;nbsp;&amp;nbsp; += -Wall -Wno-parentheses -fno-builtin&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CCFLAGS&amp;nbsp;&amp;nbsp;&amp;nbsp; += -fmessage-length=0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CCFLAGS&amp;nbsp;&amp;nbsp;&amp;nbsp; += -I$(INCL)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CCFLAGS&amp;nbsp;&amp;nbsp;&amp;nbsp; += -save-temps -fverbose-asm&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You want to set options to mimic this (esp the second line)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The last line causes the compilers asm output from the c file to be kept (as cfile.s, so DONT have a "C" and asm&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;with the same basename!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You can look at this in an editor if you want to see how C translates to asm.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Going the other way is just as easy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;a "C" call:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var = AsmFunc(buff, startVal, byteCount);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;would call your asm with r0 to r2 as described above; you would set r0 to whatever your return value is before&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the bx lr to return to the next "C" statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One last point:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Unless you do things to change the game, "C" will put code into a .text section. initialised data to .data&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and uninitialised data into .bss.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your startup code must find the beginning and end of these and where the rom copy of the data lives and&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;copy data/clear bss to zero.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are many examples of ways to do this on the forum/code red wiki, and in almost all samples (this is setup&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;so it doesn't really matter what sample it is).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There's also rodata* which you dont have to bother with as it stays in the flash (read only data).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you know this already, or is this helpful?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558613#M15091</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558614#M15092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MikeSimmonds on Fri Feb 22 20:16:02 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;[FONT=Comic Sans MS][SIZE=1]Actually, I think the point of asm calling "C" functions was so that you could call&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;things like printf.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;These [I]are[/I] library functions so you would have to link against redLib/newLib and live with the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;size of the library in your project.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And you wouldn't disable library(ies), startup files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm a bit unsure about the following, but ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The library startup code will probably take care of data/bss initialisation, but will probably&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;insist on starting at 'main' ( a "C" function)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suggest that 'main' simply calls your top-level asm code (which never returns to main)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like&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;
int main(void)
{
&amp;nbsp;&amp;nbsp; MyAsmTopLevelStartPoint();
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;As I say I don't do things like that, so it may not be exactly true.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sure that others will correct me (and tell me off).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The bits about the ABI and calling "C" from assembler are true anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558614#M15092</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558615#M15093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by cwpjr on Fri Feb 22 21:49:10 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;To Answer your Question Yes this was helpful, and I knew of the background info included so I fully understand your input. THANKS! You can ignore the rest of this.... :&amp;gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I call my asm.s entry point from main.c and can return to the point in main.c after this call, via the mov pc, lr in my asm.s code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My comments on c libs are that in some systems there are larger and smaller libs say for the stdio.h functions....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would hope to simply make c calls to void input/output c routines, passing all my parameters in the 1rst 4 registers, to avoid the call stack crap. If this is undo-able please let me know!:eek:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Alternately I could probably fudge it (again tell me if I'm being foolish) by using the lr return to main.c in a loop that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) calls my asm.s entry function, then enters a begin until loop consisting of the below steps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) when I need say c i/o I would save the lr value that goes back to main.c and set lr to return to this point in asm.s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3) at this point in main.c I would save the current lr (IF NEED BE) then continue into a case statement would call the functions I wrote and want to use, doing what ever mangling to the c call stack of my register'd arguments, if need be.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4) use the lr value set in asm.s to return to the asm.s point before the lr to main.c&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this is unclear or undo-able or been solved a clearer way let me know please!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good info to mull:cool: and I see that your examples may be simpler, if they don't hog my ARM M0 limited ram to bad...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558615#M15093</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558616#M15094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MikeSimmonds on Sat Feb 23 09:06:58 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;[FONT=Tahoma][SIZE=1]As I said, I don't use "C" libraries, rather my C is sort of top level messsge handling for most of our systems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The 'ease' and algorithm clarity overweighs the asm compactness (at least so my boss says).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also my MPU is a Cortex M3, so I apologise if I give examples that don't build on your M0 system.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a few simple funcs, strdec, strhex, strtxt that I use to print numbers (as hex, as decimal) or copy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bits of text to a buffer. Sort of do it yourself printf sections without the printf itself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I than have a (Part Specific) puts func that copys a null terminated string to a uart. [Busy waiting, no&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;interrupts etc.] &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am assuming you want to display debug/status messages over a serial comms link and have a uart&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; (+level converter) on your PCB. [If not some sort of specifics (also which MPU) might be useful.]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;And that you can setup that uart.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm happy to give these to you (and anyone else), but it will have to wait till I wake up on Sunday ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm off to a Beer Festival (Get Drunk For Charity!) so expect the worst:D for my hangover.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558616#M15094</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558617#M15095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by cwpjr on Sat Feb 23 14:35:15 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Not enough Beer charity events here in the U.S.:confused:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To Answer your Question Yes this was helpful, and I knew of the&amp;nbsp; background info included so I fully understand your input. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I get my serial hardware up I will probably ask to see the code you say you can share. Until then Thanks so much again!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;:)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers, Clyde&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558617#M15095</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558618#M15096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MikeSimmonds on Sun Feb 24 14:28:27 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;[FONT=Tahoma][SIZE=1]This is an aside -- Code in next post; But "read this first"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I re-examined my code in more detail, I see that a lot of it will not compile on an M0 part.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As you are not employing me, I am not going to do anything about that. :p&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;There are standard work arounds that you can work out for yourself for the lack of the "it" instruction&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and the "cbz/cbnz" etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;More difficult to spot are the M0's limitation on the variations of the "mov" instruction etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The biggest problem is the lack of any way to divide by 10. You will have to make (or google/steal) a&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;subroutine for this yourself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The M3 is much easier to work with when you are coding assmbler directly (in "C", someone else has&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;done the work). See poster image attached.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you 'wedded' to an M0 part? Can you upgrade to an M3 part with compatible flash/ram/peripherals.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are the 'hobby' or investigation/evaluation stage, I stongly urge a move to M3.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this an actual live project where every penny is critical, you can afford to hire (as in pay) someone to&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;shoe horn into an M0 design.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are hobby, I consider it my public duty to [I]buy[/I] you a LPCXpresso 1769 eval board to wean you off the M0's&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(But I am not going to:rolleyes:).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Having said all this, the next post is of my [I]Cortex-M3[/I] code snippets.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[Edit]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;With Cortex M3, you also get the use of the high registers (R8 to R12). Sometimes this costs more in code space,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but you do have the option.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/Edit]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558618#M15096</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558619#M15097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MikeSimmonds on Sun Feb 24 14:48:17 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;[FONT=Tahoma][SIZE=1]As promised, my number formatting code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Typically, allocate a small buffer (e.g. 128 bytes -- you can use the stack) and call a series of&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;strtext, strhex, strdec etc. to build up yor report string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[B]Don't forget[/B] to add a final null byte after the last format chunk.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The send this string to 'puts'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[B]NOTE[/B] in the puts source code, change the uart0 equate to match the register base address for the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;uart you choose to use as set out in the user manual for the device (LPC part) you are using.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The full text is too long to post, get the code from the zip:(&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[Edit]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[B]This is important too![/B]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I object very strongly to the way that ARM (the company) abribtrarily overturned 50+ (well at least 40) years of&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tradition and changed the comment character from ';' to '@' (ugly in quantity). They then suggest the we use&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the hijacked ';' as a statement seperator. Is this an attempt to make assember resemble "C" -- a forlorn attempt!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In any case, I am not prepared to put up with this, so I patch the 'arm-non-eabi-as.exe' (just have to swap two&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bytes -- as long as they are the correct two) to get back the ';' as the comment character.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Before attempting to assemble my sources, do a global replace of ';' with '@'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the editor cannot do this in one operation, get a better editor!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also change 'thumbFunc' (in amacs.inc) to 'thumb_func'. I have a serious down on underscores in names etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I should appologise for the inconvenience, but I place the original blame on ARM, so I don't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/Edit]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers, Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558619#M15097</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558620#M15098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by TheFallGuy on Sun Feb 24 15:32:55 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: MikeSimmonds&lt;/STRONG&gt;&lt;BR /&gt;[FONT=Tahoma][SIZE=1]As promised, my number formatting code.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I object very strongly to the way that ARM (the company) abribtrarily overturned 50+ (well at least 40) years of&lt;BR /&gt;tradition and changed the comment character from ';' to '@' (ugly in quantity). They then suggest the we use&lt;BR /&gt;the hijacked ';' as a statement seperator. Is this an attempt to make assember resemble "C" -- a forlorn attempt!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is no standard comment character, it depends on the architecture. See&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://"&gt;http://en.wikipedia.org/wiki/GNU_Assembler&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To quote from the above page:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Single-Line comments:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Single line comments have a few different formats varying on which architecture is being assembled for.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hash symbols are used for the platforms: i386, x86-64, i960, 68HC11, 68HC12, VAX, V850, m32r, and M880x0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Semicolons are used on: AMD 29K family, ARC, H8/300 family, HPPA,PDP-11, picoJava, Motorola, and PowerPC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The at sign is used on the ARM platform.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A vertical bar is used to signify comments when assembling on 680x0.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558620#M15098</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: Call C functions from assembly language project</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558621#M15099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MikeSimmonds on Sun Feb 24 15:48:54 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;[FONT=Tahoma][SIZE=1]&lt;/SPAN&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: TheFallGuy&lt;/STRONG&gt;&lt;BR /&gt;There is no standard comment character, it depends on the architecture. See&lt;BR /&gt;&lt;A href="http://"&gt;http://en.wikipedia.org/wiki/GNU_Assembler&lt;/A&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;SPAN&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: TheFallGuy&lt;/STRONG&gt;&lt;BR /&gt; [FONT=Tahoma][SIZE=1]&lt;BR /&gt;&lt;BR /&gt;To quote from the above page:[/SIZE][/FONT] [FONT=Tahoma][SIZE=1]&lt;BR /&gt;&lt;BR /&gt;Single-Line comments:[/SIZE][/FONT] [FONT=Tahoma][SIZE=1]&lt;BR /&gt;Single line comments have a few different formats varying on which architecture is being assembled for.&lt;BR /&gt;Hash symbols are used for the platforms: i386, x86-64, i960, 68HC11, 68HC12, VAX, V850, m32r, and M880x0.&lt;BR /&gt;Semicolons are used on: AMD 29K family, ARC, H8/300 family, HPPA,PDP-11, picoJava, Motorola, and PowerPC.&lt;BR /&gt;The at sign is used on the ARM platform.&lt;BR /&gt;A vertical bar is used to signify comments when assembling on 680x0.[/SIZE][/FONT]&lt;/SPAN&gt;&lt;HR /&gt;&lt;SPAN&gt;[FONT=Tahoma][SIZE=1]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not talking about the GNU implementation specifically [where the ARM comment details are set for&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;compatibility with ARM's assembler!], but historically.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;E.g. DEC VAX 11, Motorola 6800[0], Intel from Z80 through current 32/64 bit with MASM, 8051 and variants, PIC, AVR, etc. and others&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;that I have forgotten about or died into obscurity.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As far as my 40 years experience goes, everybody used a semi-colon until ARM. For in-line comment to eol.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not considering full line 'block'&amp;nbsp; comments (ARM uses a hash/pound/number sign -- name varies with&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;geographic location.) I have not changed this but never use it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards, Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:36:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Call-C-functions-from-assembly-language-project/m-p/558621#M15099</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:36:07Z</dc:date>
    </item>
  </channel>
</rss>

