In one of my project I am talking with MX909 Driver IC with C51 ucontroller. To initialize MX909 if I write module in Assembly language it's working fine. Once I replaced with C same module it's not working.
The only difference I can make for both assembly and C languages is NOP and _nop_() instruction. Is both instructions will take same number of machine cycles?
Thanks, Suresh Kumar Kavula
Once I replaced with C same module why on earth did you do that?
If you had taken one second to look at the generated assembly you would have found that they are identical.
My guess is that you suffer from some fallacy that e.g. a for loop is the same as a djnz loop and nothing could be farther from the truth.
If you, for some silly reason, have to "replace with C" have a look at the assembler code generated by the compiler and you will find your answer.
Erik
Erik,
Thanks for your quick response. By using keil C I am trying to generate 2.4uSeconds delay by writing 4 _nop_() instructions. For this I am using I am using AT89C5131, X1 clock Mode with 20 MHZ.
Same C routine if I replace 4 NOP instructions by using #pragma ASM working fine.
I don't know what the reason is.
ONCE MORE
LOOK AT THE ASM GENERATED BY THE COMPILER!!
Yes, disassembly generating NOP instructions only for each _nop_() instruction.
It seems problem in some where else.
Thanks a lot Erik for your help.
Yes, disassembly
That is just too cumbersome a method, why not use the .lst file?. Or to be real fancy do a 'test compile' with #pragma SRC
"Yes, disassembly generating NOP instructions only for each _nop_() instruction"
I should hope so too - that's exactly what it is defined to do: http://www.keil.com/support/man/docs/c51/c51__nop_.htm
However, this is where any code-generation guarantee ends!
It is fundamental to the nature of High-Level Languages (HLLs; including 'C') that you have absolutely no control whatsoever over the code that will be generated by the compiler.
Therefore, although the _nop_() Intrinsic Function is guaranteed to insert a single NOP instruction, you have absolutely no control whatsoever over the rest of the code that will be generated around the _nop_() "call".
Therefore, you must use an assembler routine if you need a predictable delay!
View all questions in Keil forum