Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Q: Global variables with C and ASM / pass argument from ASM to C function ?

Q: Global variables with C and ASM / pass argument from ASM to C function ?

2005-04-15 by ateichtmann

Hi,

im using CrossWorks and LPC2106 and have the following question:

I want to make a ram check before main (in the module crt0.s).
Therefore, i have to pass the result of the ram check in some way to 
main. Maybe, there are two solutions:

1. Modify the main function to pass an argument from crt0:
int main(int ResultRAMCheck)
I dont know, how to modify main() in this way and how to pass an 
argument from an assembler module to a C function.

2. define a global variable, that is known in main.c and in crt0.s
Im not sure, if this works, and i dont know how to declare global 
variables in the assembler module.

Thanks for all hints.

Regards
Arvid

Re: [lpc2000] Q: Global variables with C and ASM / pass argument from ASM to C function ?

2005-04-15 by Richard Duits

The ARM Procedure Call Standard says that the first four arguments are 
passed in R0 to R3. So if you put the ResultRAMCheck in R0 just before 
the call to the main function you are ok. I would not use a global 
variable, because it is a bit more complicated.

Regards,
Richard.


ateichtmann wrote:
Show quoted textHide quoted text
>
> Hi,
>
> im using CrossWorks and LPC2106 and have the following question:
>
> I want to make a ram check before main (in the module crt0.s).
> Therefore, i have to pass the result of the ram check in some way to
> main. Maybe, there are two solutions:
>
> 1. Modify the main function to pass an argument from crt0:
> int main(int ResultRAMCheck)
> I dont know, how to modify main() in this way and how to pass an
> argument from an assembler module to a C function.
>
> 2. define a global variable, that is known in main.c and in crt0.s
> Im not sure, if this works, and i dont know how to declare global
> variables in the assembler module.
>
> Thanks for all hints.
>
> Regards
> Arvid
>
>
>
>
>
> ------------------------------------------------------------------------
> *Yahoo! Groups Links*
>
>     * To visit your group on the web, go to:
>       http://groups.yahoo.com/group/lpc2000/
>        
>     * To unsubscribe from this group, send an email to:
>       lpc2000-unsubscribe@yahoogroups.com
>       <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>        
>     * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>       Service <http://docs.yahoo.com/info/terms/>.
>
>

Re: [lpc2000] Q: Global variables with C and ASM / pass argument from ASM to C function ?

2005-04-15 by Robert Adsett

At 12:05 PM 4/15/05 +0000, ateichtmann wrote:
>I want to make a ram check before main (in the module crt0.s).
>Therefore, i have to pass the result of the ram check in some way to
>main. Maybe, there are two solutions:
>
>1. Modify the main function to pass an argument from crt0:
>int main(int ResultRAMCheck)
>I dont know, how to modify main() in this way and how to pass an
>argument from an assembler module to a C function.
>
>2. define a global variable, that is known in main.c and in crt0.s
>Im not sure, if this works, and i dont know how to declare global
>variables in the assembler module.

You could take the simple way out.  Write a quick function in C as a 
template and compile it to asm to use as a template.  If you are doing any 
significant work though you will want an assembly reference work of some sort.

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,   be 
they legal, genetic, or physical.  If you don't believe me, try to chew a 
radio signal. "  -- Kelvin Throop, III
http://www.aeolusdevelopment.com/

Re: Q: Global variables with C and ASM / pass argument from ASM to C function ?

2005-04-15 by ateichtmann

Hi,

> You could take the simple way out.  Write a quick function in C as a 
> template and compile it to asm to use as a template.  

I have no idea, how to create an asm template.
These are the interesting and simple things that are never mentioned 
in a compiler documentation or book :-)


Regards
Arvid

Re: [lpc2000] Re: Q: Global variables with C and ASM / pass argument from ASM to C function ?

2005-04-15 by Robert Adsett

At 01:25 PM 4/15/05 +0000, ateichtmann wrote:
> > You could take the simple way out.  Write a quick function in C as a
> > template and compile it to asm to use as a template.
>
>I have no idea, how to create an asm template.
>These are the interesting and simple things that are never mentioned
>in a compiler documentation or book :-)

Most compilers have a simple switch to generate assembly as the output 
rather than an object file (something like cc -S).  That's all you 
need.  Then you can take the generated assembly file and use it as a 
template or as a tool to gather insight into the compilers operation.

The biggest use I've found for that is usually to clarify what the 
compiler's documentation has to say about the calling conventions.  Or how 
to call library internal routines, although if I have to go that far there 
is usually not much point to sticking with assembler.

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,   be 
they legal, genetic, or physical.  If you don't believe me, try to chew a 
radio signal. "  -- Kelvin Throop, III
http://www.aeolusdevelopment.com/

Re: [lpc2000] Re: Q: Global variables with C and ASM / pass argument from ASM to C function ?

2005-04-17 by 42Bastian Schick

> I have no idea, how to create an asm template.
> These are the interesting and simple things that are never mentioned
> in a compiler documentation or book :-)

Which compiler do you use ? Sounds like gcc, so if you look up the gcc 
options you'll find -S (stop after generating assembly).
So compile a simple

void a(int b)
{
}

with -S and you get your template.

But anyway, as Richard noted, define your main as void main(int result) 
and put
your result in r0.


-- 
42Bastian Schick

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.