We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Can any one tell me how to mix C and Assembly in kiel in a single file?
Thanks in advance
Since you call this a "Generic" question, only a generic answer can be given: Read the Manual
Hint: look for a section titled, "interfacing C and assembler" - the clue is in the name!
Hi Neil,
which manual? Can u name it?
"which manual? Can u name it?"
If you can't be bothered to type those 2 extra characters to make "you", then I can't be bothered to go leafing through manuals for you!
All the manuals are available online: http://www.keil.com/support/man/
It shouldn't take you long to work out which is the appropriate one...
we have to use #pragma directive
#ASM ...(ASM code)
#ENDASM
make a few changes in the compiling Environment, like generate src file, ...
Try C51 pdf that comes along with Keil Help documentation. Now thats the procedure in which it should work. If it works fine do let me know. When i tried , no errors, but didnt work .
"we have to use #pragma directive"
Without knowing what compiler he's using, this could be complete rubbish.
"#ASM ...(ASM code) #ENDASM"
Again, without knowing what compiler he's using, this could be complete rubbish. If he is using C51, it is rubbish!
"Try C51 pdf that comes along with Keil Help documentation"
But only if he's using C51!
you are right had assumed it to be c51 i guess
I can't find the RealView manuals online.
I'm trying to add some assembly code to a RealView ARM (AT91SAM7S) project and am not getting very far. I found the "Interfacing C and Assembly" advanced programming topic, but am not sure it's applicable, since it's under a CARM (rather than a RealView) heading. I tried copying the example code from that topic and putting it into my RealView project, but I get errors out the kazoo starting on the first line. I searched for "interfacing" in the RealView Assembler Guide, but it's not there. I also tried putting #pragma SRC at the top of a small C file to see if that would help, but in RealView, it doesn't look like that pragma is supported, and I haven't been able found a pragma that looks like it replaces the SRC pragma yet (bummer!).
Can anyone point me to (1) where the RealView manuals are online, and (2) to a sample RealView compatible (bare bones, small, simple) assembly file that I can use as a template to help get started (maybe for something as simple as a function that just toggles the state of an I/O pin), and (3) an app note (or something) that shows how to interface C and assembly with the RealView tools?
EDITORIAL COMMENT: I sure wish I would've received hard copy manuals from KEIL when I upgraded to RealView. Nothing like kicking back in a comfortable recliner with my feet propped up for some serious reading. Reading PDF files on a PC is no fun for me. Can't put bookmarks in them, can't dog-ear pages, can't highlight text or add annotations, can't stuff prinout's in them... I could go on and on. Printing out a 464 page PDF file is not an option for me.
Okay... here's something that seems to work. Simply put this code into a .S file and add it to your project.
AREA |.text|, CODE, READONLY ARM PIOA_SODR EQU 0xFFFFF430 ; set output data register PIOA_CODR EQU 0xFFFFF434 ; clr output data register IOPIN_PA8 EQU 0x1<<8 ; I/O pin PA8 (1 << 8) ALIGN myfunc FUNCTION EXPORT myfunc MOV R1,#IOPIN_PA8 LDR R0,=PIOA_SODR STR R1,[R0,#0] LDR R0,=PIOA_CODR STR R1,[R0,#0] BX LR ENDFUNC END
Then add the below line to the C file you want to call 'myfunc' from,
extern void myfunc(void);
and then just call
myfunc();
from your C file. Works for me. Of course, there might be more to it, but this seems to have been enough for me to create a function in a RealView compatible ASM file that just toggles an I/O pin that I can then call from a C file in a RealView project. Dave :-)
Hello Dave,
Glad to see that you are still around. Gotta say, though, that you really need to get out more and have some fun ;-)
ARM? Now I know why I haven't heard from you in ages. What happened? Did you change jobs, or just architectures?
Take care.
Regards,
Mark Fabiny Infineon Technologies