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 want to get the value of the carry flag (after shift to left) from c code how to do it?? thanks
i want to get the value of the carry flag (after shift to left) from c code how to do it??
The CY bit should be defined in your processor-specific .h file.
However:
Don't do it. Messing around with registers in C is a good way to create a maintenance and debugging nightmare. There is no specified way that these registers behave in C.
Write a short assembly routine that does what you're trying to accomplish and call it from C. This is the clean way to do it.
As Christoph says, it is possible - but definitely not advisable.
Sure, you can access the CY flag in 'C' - but you can never be sure that it relates to the operation that you think and/or require...
The only safe way, as Christoph says, is to use assembler and call it from 'C'.
i want to get the value of the carry flag (after shift to left) from c code one answver The only safe way, as Christoph says, is to use assembler and call it from 'C'.
in C, the same is possible, but by other means:
bit flag;
flag = 0; if (var &0x80) flag = 1; var <<= 1;
use 'flag' as you would CY
Erik
the trigger to use the carry is to remove the "if" ...
consult Jack Sprat, he will tell you to read the manual and see this is how it is, whether you like it or not. C is a magificent product, nobody is to quesation it.
Don't use internal registers in C! Neither ACC nor B, R0-R7, DPTR and so on.
If you have to use the carry bit CY: Try to use an equivalent algorithm (see the suggestion from Erik). If this is not possible or insufficient, then use the alternative solution: It's highly recommended to use CY either as inline assembler (#pragma asm ... #pragma endasm) of a .C51 module/function or in an external .A51 assembler module/function. And, of course, with own proper initialization of ACC in your asm statements, don't rely on the contents of ACC by the C-compiler!
This suggestion is also valid for checking the parity bit P, which has the same problem as CY.
I often use this technique, e.g. when decoding DCF77 radio clock signal (which has three parity bits).
Martin
"It's highly recommended to use CY either as inline assembler (#pragma asm ... #pragma endasm) of a .C51 module/function or in an external .A51 assembler module/function."
I highly recommend that you should not use inline assembler - use an external .A51 assembler module/function and call it from 'C'
Inline Assembler is still subject to the risk of false assumptions about the states of internal registers!