Mix C&Assembly with Keil C51/A51

Dec 18, 2005 11 Replies

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


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

are

main

assembly in

the

:)

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.

In article , Nappy writes

Try:

unsigned long data burnAddress;

unless you are already compiling in the SMALL model.

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

formatting link

Rickey wrote: >

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:

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.

oh plz chk. what a petty wrthls pst.

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.

parts)

???)

does

Thank you Neil.

which

the

char

address

I

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

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required