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 can generate the JC instruction with the Keil C compiler

HI,Dear all,

I did'nt want to use the SRC and ASM,How can Gen the JC instruction in keil?such as
following.
I used three byte,but used the union struct must define a double word var,You know,The Keil will gen a assemble code more waste the CPU time.So I have following code,to finish a add with 3-byte,but the keil compiler is not smart.

CY = 0;
V_0 += 0x07;
if(CY)
{
CY = 0;
V_1 += 1;
if(CY)
{
CY = 0;
V_2 += 1;
}
}
**********************************
; CY = 0;
; SOURCE LINE # 1254
CLR CY
; V_0 += 0x07;
; SOURCE LINE # 1255
MOV A,#07H
ADD A,V_0
MOV V_0,A
;
; if(CY)
; SOURCE LINE # 1257
JNB CY,?C0017
; {
; SOURCE LINE # 1258
; CY = 0;
; SOURCE LINE # 1259
CLR CY
; V_1 += 1;
; SOURCE LINE # 1260
INC V_1
;
; if(CY)
; SOURCE LINE # 1262
JNB CY,?C0017
; {
; SOURCE LINE # 1263
; CY = 0;
; SOURCE LINE # 1264
CLR CY
; V += 1;
; SOURCE LINE # 1265
INC V_2
; }

Parents
  • Hi,
    I did'nt want to use the SRC and ASM,How can Gen the JC instruction in keil?
    I do not want to do anything but wish to have billions $$$, gimmy how todo! (=
    First of all, your example cannot be optimized with JBC (look at the source more careful to know why; HINT: in this case it requires with two additional GOTO).
    Secondly: when you need with high-optimized code and see that C-compiler cannot give you needed result - why do you not use ASM/ENDASM macro?
    Okay, now, perhaps you will be surprised about that CY = 0; is not compiled into CLR C. Keil translates it into two-bytes instruction (exactly to "clear bit" instruction with op-code 0xC2 0xbit_number). CLR C is another instruction which takes only one byte of code (it is separate instruction called "clear carry flag" with op-code 0xC3). Do not ask me why does it do such way - I am not the author of the compiler (= It seems that the compiler takes carry flag as a part of the rest bits and not pay attention that there are some assembly commands related to carry flag especially (here I mean the usage CLR C instead of CLR PSW.7). Just ask authors to implement this feature in the future.
    Anyway, you have a choice: either use LONG variable or make short in-line ASM block - both are useful. As for me so I preffer to write all the program with pure asm; oh well, Erik - kick me then (=

    cu

Reply
  • Hi,
    I did'nt want to use the SRC and ASM,How can Gen the JC instruction in keil?
    I do not want to do anything but wish to have billions $$$, gimmy how todo! (=
    First of all, your example cannot be optimized with JBC (look at the source more careful to know why; HINT: in this case it requires with two additional GOTO).
    Secondly: when you need with high-optimized code and see that C-compiler cannot give you needed result - why do you not use ASM/ENDASM macro?
    Okay, now, perhaps you will be surprised about that CY = 0; is not compiled into CLR C. Keil translates it into two-bytes instruction (exactly to "clear bit" instruction with op-code 0xC2 0xbit_number). CLR C is another instruction which takes only one byte of code (it is separate instruction called "clear carry flag" with op-code 0xC3). Do not ask me why does it do such way - I am not the author of the compiler (= It seems that the compiler takes carry flag as a part of the rest bits and not pay attention that there are some assembly commands related to carry flag especially (here I mean the usage CLR C instead of CLR PSW.7). Just ask authors to implement this feature in the future.
    Anyway, you have a choice: either use LONG variable or make short in-line ASM block - both are useful. As for me so I preffer to write all the program with pure asm; oh well, Erik - kick me then (=

    cu

Children
  • The day that a C compiler is "perfect" will never happen. By the old rule 80% of the improvement can be acieved by 20% of the effort and with the market for customers willing to pay 5 times more than currently for a C compiler being minuscule, do not expect the comiler makers to milk every little bit of efficiency.

    Erik