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
  • CY=PinBit;              //generates MOV C,PinBit
    ...
    if(CY)
    

    Now that's a profoundly bad idea. You're writing C, not assembly. That means you do not, repeat: not, own the CPU registers. The compiler needs them for its own work.

    Whatever made you assume that you could rely on the value of PinBit still being in the carry flag, after whatever actually is hidden inside that "..."?

    The answer to you question is: don't do that. Try to even avoid thinking about doing that.

Reply
  • CY=PinBit;              //generates MOV C,PinBit
    ...
    if(CY)
    

    Now that's a profoundly bad idea. You're writing C, not assembly. That means you do not, repeat: not, own the CPU registers. The compiler needs them for its own work.

    Whatever made you assume that you could rely on the value of PinBit still being in the carry flag, after whatever actually is hidden inside that "..."?

    The answer to you question is: don't do that. Try to even avoid thinking about doing that.

Children
No data