??? 04/03/05 07:09 Read: times |
#90893 - efficiency Responding to: ???'s previous message |
Raghu, this version works OK, but please allow me couple of remarks on efficiency. I'll bet, you have extensive experience on non-51 processors; I have seen many times similarly inefficient programming style from people, who are not aware of all the peculiarities of '51 core processor. In the CHKLUP loop, you are checking if MIRHEX1 and MIRHEX2 variables are the same value, using SUBB. On '51, you can use a single instruction - CJNE - both for compare and conditional jump, so you can spare a couple of instructions: MOV A,MIRHEX1 CJNE A,MIRHEX2,CHKLUPFurthermore, as MIRHEX2 is only holding a constant, you can use it directly in the comparison. And, as accumulator don't gets destroyed by the comparison, you can hold the processed value in the accumulator itself, eliminating the need for both variables. So the loop now shrinks to CHKLUP: INC DPTR DEC A CJNE A,#0FFh,CHKLUPBut we can also compare accumulator to any value, including zero, if we shift the table accordingly; so we can use DJNZ ACC,CHKLUP sparing one more instruction in the loop (now the output value for input=1 must be the first one in the table, and the output value for 0 the last one) . Following the loop, there is MOV A,#0, for which the '51 has a one-byte one-cycle dedicated instruction - CLR A. But if you realize that the MOVC instruction employs accumulator as an offset to DPTR (or PC), the whole routine collapses to MOV DPTR,#INV_HEX MOVC A,@A+DPTR RET Jan Waclawek |