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 ; }
Uhhh. The Keil compiler supports the long and unsigned long types which are 32-bit. They are already fully implemented and supported. Why re-create the wheel? Jon
Sir, Yes,but you know,if you will send a mass data to a device,the long var will waste the CPU much time do the null work, such as: for(i = 0x10000;i != 0; i--) long var ++ The result is very bad, you can try
"Yes,but you know,if you will send a mass data to a device,the long var will waste the CPU much time do the null work," What on earth are you talking about?! If you need to handle 32-bit numbers, then using the compiler's built-in support will be more efficient than trying to code it yourself at the 'C' source level! Of course, if you use 32-bit data types when you don't need to, then you will obviously be wasting a lot of code space & CPU time!
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
If you need to handle 32-bit numbers Well, look at Paddy's example a bit closer, and you'll find that what it really needs is a 17-bit number (or an exploitable carry-bit) for his loop of exactly 65536 iterations. But C only offers integer types with either 16 or 32 bits. So yes, he does need to handle 32-bit numbers, if he wants to keep within the limits of C, but it'll still be wasteful, because it updates a value almost twice as wide as it really has to be. A 24-bit C integer type supported by the compiler could help, here, but it doesn't exist. In assembly, this could be done by checking the carry bit after decrementing the hibyte of a 16-bit number, but in C, that's not available. To work around this, one can use an accepting loop construct and exploit unsigned roll-over:
unsigned char i = 0; do { /* do something */ i ++ } while (i != 0);
unsigned char i = 0xff; while (1) { /* do something */ if (i == 0) break; i--; }
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