Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Mix C&Assembly with Keil C51/A51

6 views
Skip to first unread message

Nappy

unread,
Dec 18, 2005, 11:38:13 AM12/18/05
to
I am having a difficult time combining C and assembly in the Kiel
development environment.
I have a progtram which is mainly in C. I have assembly modules which are
inline code.
The assembly modules have to access variables which are defined in the main
C area.
I am using the EXTRN command in my inline ASM area for at least one char
variable.
ex:
EXTRN DATA(curSector)

I now have an unsigned long which was being passed to the inline assembly in
the Registers. That works, of course. But I wanted to directly address the
long variable in my assembly code to eliminate the need to prep the
registers prior to the call.

so I have

unsigned long burnAddress ; defined in the C code

in the inline assembly I have:

EXTRN DATA (burnAddress)

and I access it like this:

mov a,burnAddress ; MSB
..
mov a,burnAddress +1
..
mov a,burnAddress +2
..
mov a,burnAddress +3 LSB

Is this correct?

Thanks

eng


Tauno Voipio

unread,
Dec 18, 2005, 2:12:32 PM12/18/05
to

Yes.

A long needs four bytes, but the accumulator fits only
one at a time, so you need four fetches.

--

Tauno Voipio
tauno voipio (at) iki fi

Nappy

unread,
Dec 18, 2005, 3:37:44 PM12/18/05
to

"Tauno Voipio" <tauno....@INVALIDiki.fi> wrote in message
news:Awipf.380$2x4...@read3.inet.fi...


:)

Yes. I was asking about the proper connection for the linker. As it seems I
am not getting the proper values in the assembly.

Thanks.

Stephen

unread,
Dec 18, 2005, 7:11:52 PM12/18/05
to
In article <Vfgpf.42969$6e1....@newssvr14.news.prodigy.com>, Nappy
<noe...@all.com> writes

>I am having a difficult time combining C and assembly in the Kiel
>development environment.
>I have a progtram which is mainly in C. I have assembly modules which are
>inline code.
>The assembly modules have to access variables which are defined in the main
>C area.
>I am using the EXTRN command in my inline ASM area for at least one char
>variable.
>ex:
>EXTRN DATA(curSector)
>
>I now have an unsigned long which was being passed to the inline assembly in
>the Registers. That works, of course. But I wanted to directly address the
>long variable in my assembly code to eliminate the need to prep the
>registers prior to the call.
>
>so I have
>
>unsigned long burnAddress ; defined in the C code

Try:

unsigned long data burnAddress;

unless you are already compiling in the SMALL model.

Rickey

unread,
Dec 19, 2005, 3:24:29 AM12/19/05
to
or you can use unsigned long idata burnAddress;
what are the errors or problems you are getting? i mean can you plz be
more specific bout them. so that i can help you in a better way ;-)
reagards,
ajay bhargav
www.rickeyworld.tk

Chuck F.

unread,
Dec 19, 2005, 10:13:38 AM12/19/05
to
Rickey wrote:
>
> or you can use unsigned long idata burnAddress; what are the
> errors or problems you are getting? i mean can you plz be more
> specific bout them. so that i can help you in a better way ;-)

Google is not Usenet, nor is their broken Usenet interface in any
way representative of the view others have. In order to make your
posts intelligible you MUST include context. See below for means
of so doing even on Google

In addition you should avoid silly spelling mistakes and
abbreviations, such as the use of i (in place of I) and plz. This
greatly improves readability.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>

Nappy

unread,
Dec 20, 2005, 1:32:31 PM12/20/05
to

"Chuck F. " <cbfal...@yahoo.com> wrote in message
news:Ic2dnZ6Z3N44fDve...@maineline.net...

> Rickey wrote:
> >
> > or you can use unsigned long idata burnAddress; what are the
> > errors or problems you are getting? i mean can you plz be more
> > specific bout them. so that i can help you in a better way ;-)

Oh Please Chuck..

Nappy

unread,
Dec 20, 2005, 1:37:33 PM12/20/05
to

"Rickey" <bharga...@gmail.com> wrote in message
news:1134980669.5...@g49g2000cwa.googlegroups.com...

I am trying to milk every nanosecond of speed out of a design and I have a
routine which is currently being passed a LONG in registers. And I was
looking to remove the time it took to load them prior to the call. So I am
attempting to access the long in the routine as:

mov a,burnAddress
..
mov a,burnAddress+1

etc.

But I am getting the wrong data.

When using inline assembly with uVision I can not get the CODE in the
listings so suppose I have to inspect the opcodes in the hex file..

The default data area for this variable would be DATA.


Nappy

unread,
Dec 20, 2005, 1:37:57 PM12/20/05
to

> Google is not Usenet, nor is their broken Usenet interface in any
> way representative of the view others have. In order to make your
> posts intelligible you MUST include context. See below for means
> of so doing even on Google
>
> In addition you should avoid silly spelling mistakes and
> abbreviations, such as the use of i (in place of I) and plz. This
> greatly improves readability.
>
> --
> "If you want to post a followup via groups.google.com, don't use
> the broken "Reply" link at the bottom of the article. Click on
> "show options" at the top of the article, then click on the
> "Reply" at the bottom of the article headers." - Keith Thompson
> More details at: <http://cfaj.freeshell.org/google/>

oh plz chk. what a petty wrthls pst.


Neil Kurzman

unread,
Dec 20, 2005, 11:39:40 PM12/20/05
to

Nappy wrote:

Rule of thumb with Keil.
Write the sub in C and look at the asm. ( Or at least the data access parts)
if the var is define in C you may get that Underscore thing (_burnAddress ???)

Try it with an int first I THINK Keil calls internal libs for long, but does
ints in place.
That varies by compiler version I guess.


Nappy

unread,
Dec 21, 2005, 10:52:21 AM12/21/05
to

"Neil Kurzman" <n...@mail.asb.com> wrote in message
news:43A8DB85...@mail.asb.com...

>
> Rule of thumb with Keil.
> Write the sub in C and look at the asm. ( Or at least the data access
parts)
> if the var is define in C you may get that Underscore thing (_burnAddress
???)
>
> Try it with an int first I THINK Keil calls internal libs for long, but
does
> ints in place.
> That varies by compiler version I guess.
>
>

Thank you Neil.


bis

unread,
Dec 29, 2005, 7:41:08 AM12/29/05
to


Check if Keil realy use big endian for storing long variables. May be you
need to exchnge MSB with LSB.

0 new messages