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.
hi ..i am new to embedded systems ... i am using uvision from keil .. i just wanna include one line assembly code .. into my c-code .. example -- nop (no operation ) assembly instuction into my c code .. how do we do it ??? thanks .. pruthvi
Hi, read C51 manual, especially about #pragma asm and Interfacing C Programs to Assembler Regards, Oleg
Check intrins.h to see if nop is defined there. If so it would be as simple as including the following lines of code in your C-file.
#include <intrins.h> _nop_();
1) the way Keil handles asm in C is - at best - crummy. It totally destroy your ability to see the original code in the emulator and require a two pass compilation-assembly. 2) if it really is a nop you want to insert Keil has provided a workaround _nop_() will insert a nop in your code. Erik
Don't do it! It's not just me saying that: http://www.8052.com/forum/read.phtml?id=63641 If you have a specific piece of code that needs to be in assembler, then write it in assembler! You can easily call assembler from 'C' - Please read the manual.
Andy, There is a big difference between fiddling with registers in a C program and inserting a nop. When you are using a processor with pipeline it is sometimes neccessary to use a nop here and there. Using a language extension is not ideal but I perfer it over reverting to assembly just to avoid it.
"There is a big difference between fiddling with registers in a C program and inserting a nop." True - but he only cited the nop thing as an example. Using inline assembler just for a nop is, in itself, a very silly thing to do: as Erik said, it destroys all your source debug info - and for no reason at all because Keil provide the _nop_() intrinsic fubction for this very purpose! Arguments about portability seem pointless here, as the issues concerned are inherently target and/or tool specific! Using inline assembler also overrides uVision's dependency checking, so that such module are always rebuilt - whether they need it or not (and it's a double translation - as Erik also said)
Andy, I think we are in complete agreement. When you said "Don't do it", I thought you meant not to use the intrinsic functions either (which is what both Erik and I recommended). I never use inline assembly, I toyed around with it once and decided it was too much of a headache.