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 have a pretty big file that during it's performance, in a specific place of the code flow, I would like to wait for exactly 4 clock cycles. The best way for me to do this, is using the empty line command (; // nop). Unfortunately, this doesn't produce any ASM code line (why ? maybe it was optimized ?) Next, I tried to add an the following lines: #pragma asm NOP; NOP; NOP; NOP; #pragma endasm and have enabled the SRC directive for this particular file from the Keil uVision. This works, but with one limitation: the whole file was translated into assembler file, not just these 4 lines, and this cause the debug operation to be much harder (when runing step-by-step, for example). Is there a way to tell the complier to create an assembler code for this NOP section only ? Can you think of any other (better) way to achive the required goal ? Thanks, Amit A.
more information: Even if cancelling the optimizer using #pragma save #pragma optimize (0) .. .. ; // nop ; // nop ; // nop ; // nop .. .. .. #pragma restore the ; // nop lines dosn't translate into ASM NOPs. I am using the following tools set: IDE-Version: µVision3 V3.05c Tool Version Numbers: Toolchain Path: C:\Keil\C51\BIN\ C Compiler: C51.Exe V7.50 Assembler: A51.Exe V7.10 Linker/Locator: BL51.Exe V5.12 Librarian: LIB51.Exe V4.24 Hex Converter: OH51.Exe V2.6 CPU DLL: S8051.DLL V2.45 Dialog DLL: DCORE51.DLL V2.45 Target DLL: BIN\DCD_DoCD.DLL V1.04 Dialog DLL: TP51.DLL V2.45
Is there a way to tell the complier to create an assembler code for this NOP section only ? How about the _nop_ library function? Jon
"The best way for me to do this, is using the empty line command (; // nop). Unfortunately, this doesn't produce any ASM code line (why ? maybe it was optimized ?)" Sounds like you need to brush-up on the basics of how a compiler works! The compiler only generates code for executable source lines - a comment is not executable! Even Assembler doesn't generate NOPs for comment-only lines! "have enabled the SRC directive for this particular file from the Keil uVision. This works, but with one limitation: the whole file was translated into assembler file, not just these 4 lines" That is not a limitation - that is exactly what the SRC directive is supposed to do, and exactly what the manual says it will do! This is one reason why inline assembler is a bad idea in C51. "this cause the debug operation to be much harder (when runing step-by-step, for example)." and that's another! You also lose all your 'C' symbol information! Search this forum for more reasons! "Is there a way to tell the complier to create an assembler code for this NOP section only ?" In pure ANSI 'C', no. But, as Jon has already said, Keil C51 provides the _nop_() intrinsic function - look it up in the Manual
Neil, If you will look carefully, you will see a semicolon before the "// nop" remark. the semicolon is the reason for me to expect the Compiler to generate a NOP ! The "//nop" remark after the semicolon was written only as a documentation to explain the semicolon. About the _nop_ function - this information helped me, I was not aware for it, and it was exactly what I was looking for. Jon, Thanks for this info. About the SRC functionality - I have read the manual and realised that this would be the outcome. I was asking if anyone knows a way for mixing ASM code in C code that is better then the one mentioned above. Amit.
If you will look carefully, you will see a semicolon before the "// nop" remark. the semicolon is the reason for me to expect the Compiler to generate a NOP !" No, you should not expect a 'C' null statement to generate a NOP. (In fact, you should not expect any 'C' source line to generate any specific machine instructions - the choice of instructions is entirely at the Compiler's discretion) "About the _nop_ function - this information helped me, I was not aware for it" Perhaps now would be a good time for you to familiarise yourself with the C51 Manual, so you don't miss any other useful bits? "I was asking if anyone knows a way for mixing ASM code in C code that is better then the one mentioned above." IF parts of your code need to be in assembler, write them in assembler in separate assembler source file(s) and call them from 'C'. Do not mess about trying to mix assembler into your 'C' source files. There is a whole section in the C51 Manual about interfacing 'C' and Assembler.