This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to use JNC or JC from C

I want to generate very efficient code using the carry-bit from C-code, and the instructions JNC or JC.

...
sbit PinBit= P0^0;              //port-IO bit
...
CY=PinBit;              //generates MOV C,PinBit
...
if(CY)
{
        //do something
}
IfNotCY:
...

The if(CY) instructiuons generates JNB CY,IfNotCY

How can i get it to use the more efficient JNC IfNotCY?

Analogously, if(!CY) should generate JC {label}.

Parents Reply Children
  • Perhaps the code example was bad, what i am trying to do is this:

    sbit PinBit= P0^0;      //port-IO bit
    CY=PinBit;      //Save off the pin-state in Carry
    ...
    // do a bunch of stuff,
    // that is guaranteed not to use the carry-bit
    ...
    if(CY)
    {
            //do something
    }
    
    This is an extremely time critical function, where i have to scrutinize every clock cycle used.
    
    
    

  • "This is an extremely time critical function, where i have to scrutinize every clock cycle used."

    Then I'd simply write it in assembly, perhaps first having created the module framework by compiling some C to assembly source using the SRC directive.

  • "i have to scrutinize every clock cycle used."

    You cannot ever guarantee that any particular 'C' source line will generate any specific sequence of machine instructions.

    That's the whole point of a high-level language - you trade-off control of the generated code for (generally) increased programmer productivity.

    Therefore, in any case where you must "scrutinize every clock cycle used", you just have to use assembler.
    There is no choice.

  • Thanks for the feedback. it works flawlessly in assembly, i was just trying to stick with C, to make readabillity and debugging easier.

  • "i was just trying to stick with C, to make readabillity and debugging easier."

    Exactly - that's the (potential) programmer productivity gain from using a HLL.

    But, when absolute timing control is critical, you have nothing to trade - you must stick with assembler.

    But be sure to be extra careful in the documentation of your assembler - well documented, well structured assembler need not be hard to debug or maintain!