Yahoo Groups archive

Lpc2000

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

Thread

Mixing assembly and C...

Mixing assembly and C...

2004-02-20 by Musharraf Hanif

Hello all,

I am using Keil with a GNU compiler in an attempt to develop some code.

I have been trying to determine some method by which I can obtain the value 
of the addresses of some lables (in assembly) to use them in my C code. Can 
anyone help me?

Also, how can I use some constants defined in some c/h file in an assembly 
file. Similarly for a reversed situation.

Any help will be appreciated.

Regards,

Musharraf Hanif

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail

Re: Mixing assembly and C...

2004-02-21 by entell0

I am not 100% sure about how GNU compiler and assembler handle
things, but in general, if you don't mind using global variables,
then you can declare them in your C environment and reference them in 
your assembly code. This will allow you to access these global 
variables from both worlds.

Alternatively, if you are going to use local variables instead of 
global ones, you can call your assembly routine from your C code and 
pass the local variables through the function arguments. If you pass 
the variables by reference, you should be able to modify their values 
as well which would allow you to copy the values of your labels in 
the assembly world into these arguments and pass them back to the C 
world.

Lastly, if you are planning to use inline assembly, I am afraid
I am not too sure what you can and can't do. You might be able
to just put the name of the variable with an underscore in front 
of it in your inline assembly code and access it that way.

Hope this helps a little.


Emrah


--- In lpc2000@yahoogroups.com, "Musharraf Hanif" 
<musharraf_hanif@h...> wrote:
> Hello all,
> 
> I am using Keil with a GNU compiler in an attempt to develop some 
code.
> 
> I have been trying to determine some method by which I can obtain 
the value 
> of the addresses of some lables (in assembly) to use them in my C 
code. Can 
> anyone help me?
> 
> Also, how can I use some constants defined in some c/h file in an 
assembly 
Show quoted textHide quoted text
> file. Similarly for a reversed situation.
> 
> Any help will be appreciated.
> 
> Regards,
> 
> Musharraf Hanif
> 
> _________________________________________________________________
> Tired of spam? Get advanced junk mail protection with MSN 8. 
> http://join.msn.com/?page=features/junkmail

RE: [lpc2000] Re: Mixing assembly and C...

2004-02-21 by Musharraf Hanif

What I am really trying to do is to setup vectored IRQs.

I am using assembly interrupt wrappers for ISRs in C. I want to write the 
function for setting up the VIC in C. Hence I need to know the starting 
address of my assembly wrappers in C. If I write the setup code for the VIC 
in assembly, then there is no problem as I can use the lables.

On a slightly different note, i have a few definitions (.equ) in the 
startup.s file. Is it possible to access their values in C? or if i shift 
these definitions to a .h file (#define), can I use them in assembly?

Are there any other forums are there where I might find people who might be 
able to help me?

Regards,

Musharraf


>From: "entell0" <ediril@...>
>Reply-To: lpc2000@yahoogroups.com
>To: lpc2000@yahoogroups.com
>Subject: [lpc2000] Re: Mixing assembly and C...
>Date: Sat, 21 Feb 2004 05:02:09 -0000
>
>
>
>I am not 100% sure about how GNU compiler and assembler handle
>things, but in general, if you don't mind using global variables,
>then you can declare them in your C environment and reference them in
>your assembly code. This will allow you to access these global
>variables from both worlds.
>
>Alternatively, if you are going to use local variables instead of
>global ones, you can call your assembly routine from your C code and
>pass the local variables through the function arguments. If you pass
>the variables by reference, you should be able to modify their values
>as well which would allow you to copy the values of your labels in
>the assembly world into these arguments and pass them back to the C
>world.
>
>Lastly, if you are planning to use inline assembly, I am afraid
>I am not too sure what you can and can't do. You might be able
>to just put the name of the variable with an underscore in front
>of it in your inline assembly code and access it that way.
>
>Hope this helps a little.
>
>
>Emrah
>
>
>--- In lpc2000@yahoogroups.com, "Musharraf Hanif"
><musharraf_hanif@h...> wrote:
> > Hello all,
> >
> > I am using Keil with a GNU compiler in an attempt to develop some
>code.
> >
> > I have been trying to determine some method by which I can obtain
>the value
> > of the addresses of some lables (in assembly) to use them in my C
>code. Can
> > anyone help me?
> >
> > Also, how can I use some constants defined in some c/h file in an
>assembly
> > file. Similarly for a reversed situation.
> >
> > Any help will be appreciated.
> >
> > Regards,
> >
> > Musharraf Hanif
> >
> > _________________________________________________________________
> > Tired of spam? Get advanced junk mail protection with MSN 8.
> > http://join.msn.com/?page=features/junkmail
>

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus

Re: [lpc2000] Re: Mixing assembly and C...

2004-02-21 by capiman@t-online.de

I can't tell you exactly how it is with GNU ARM compiler / assembler.
But in VC under Windows, the C names are expanded with an additional "_" in
Assembler.
e.g.

C Funktion "test" gets "_test" in Assembler.

Alternativly you can use something like

PUBLIC C test

Don't know if this is equal in GNU / ARM environment

Perhaps it helps...

Regards,

         Martin

----- Original Message ----- 
From: "Musharraf Hanif" <musharraf_hanif@...>
To: <lpc2000@yahoogroups.com>
Sent: Saturday, February 21, 2004 9:15 AM
Subject: RE: [lpc2000] Re: Mixing assembly and C...


> What I am really trying to do is to setup vectored IRQs.
>
> I am using assembly interrupt wrappers for ISRs in C. I want to write the
> function for setting up the VIC in C. Hence I need to know the starting
> address of my assembly wrappers in C. If I write the setup code for the
VIC
> in assembly, then there is no problem as I can use the lables.
>
> On a slightly different note, i have a few definitions (.equ) in the
> startup.s file. Is it possible to access their values in C? or if i shift
> these definitions to a .h file (#define), can I use them in assembly?
>
> Are there any other forums are there where I might find people who might
be
Show quoted textHide quoted text
> able to help me?
>
> Regards,
>
> Musharraf
>
>
> >From: "entell0" <ediril@...>
> >Reply-To: lpc2000@yahoogroups.com
> >To: lpc2000@yahoogroups.com
> >Subject: [lpc2000] Re: Mixing assembly and C...
> >Date: Sat, 21 Feb 2004 05:02:09 -0000
> >
> >
> >
> >I am not 100% sure about how GNU compiler and assembler handle
> >things, but in general, if you don't mind using global variables,
> >then you can declare them in your C environment and reference them in
> >your assembly code. This will allow you to access these global
> >variables from both worlds.
> >
> >Alternatively, if you are going to use local variables instead of
> >global ones, you can call your assembly routine from your C code and
> >pass the local variables through the function arguments. If you pass
> >the variables by reference, you should be able to modify their values
> >as well which would allow you to copy the values of your labels in
> >the assembly world into these arguments and pass them back to the C
> >world.
> >
> >Lastly, if you are planning to use inline assembly, I am afraid
> >I am not too sure what you can and can't do. You might be able
> >to just put the name of the variable with an underscore in front
> >of it in your inline assembly code and access it that way.
> >
> >Hope this helps a little.
> >
> >
> >Emrah
> >
> >
> >--- In lpc2000@yahoogroups.com, "Musharraf Hanif"
> ><musharraf_hanif@h...> wrote:
> > > Hello all,
> > >
> > > I am using Keil with a GNU compiler in an attempt to develop some
> >code.
> > >
> > > I have been trying to determine some method by which I can obtain
> >the value
> > > of the addresses of some lables (in assembly) to use them in my C
> >code. Can
> > > anyone help me?
> > >
> > > Also, how can I use some constants defined in some c/h file in an
> >assembly
> > > file. Similarly for a reversed situation.
> > >
> > > Any help will be appreciated.
> > >
> > > Regards,
> > >
> > > Musharraf Hanif
> > >
> > > _________________________________________________________________
> > > Tired of spam? Get advanced junk mail protection with MSN 8.
> > > http://join.msn.com/?page=features/junkmail
> >
>
> _________________________________________________________________
> MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
> http://join.msn.com/?page=features/virus
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>

RE: [lpc2000] Re: Mixing assembly and C...

2004-02-21 by Robert Adsett

At 08:15 AM 2/21/04 +0000, you wrote:
>What I am really trying to do is to setup vectored IRQs.
>
>I am using assembly interrupt wrappers for ISRs in C. I want to write the
>function for setting up the VIC in C. Hence I need to know the starting
>address of my assembly wrappers in C. If I write the setup code for the VIC
>in assembly, then there is no problem as I can use the lables.

You want to do something like this ?

void Startup( void)
{
  SetupVICentry( InterruptRoutine, InterruptEntry);
}

Where InterruptRoutine is your wrapper.  And SetupVICentry uses the 
routine's address to do whatever setup it needs?

Just declare your wrapper InterruptRoutine as global in the assembly with 
.global.

By far the easiest way to to figure out the C to asm interface is to 1) 
read the calling standard (it's on ARM's website) and 2) generate asm from 
sample C to walk through how that works in actual practice.

gas has the option of using the C preprocessor I believe.

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

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.