asm endasm and src directive, combining C and ASM languages

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.

Parents
  • "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

Reply
  • "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

Children
More questions in this forum