Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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,CHKLUP
Furthermore, 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,CHKLUP
But 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

List of 36 messages in thread
TopicAuthorDate
Reversing Algorithm            01/01/70 00:00      
   remembered this one            01/01/70 00:00      
      the fastest code in the west            01/01/70 00:00      
         Am I wrong            01/01/70 00:00      
            not as simple, but less table            01/01/70 00:00      
               lookup table            01/01/70 00:00      
                  nope            01/01/70 00:00      
                     swap, the nibble mirror            01/01/70 00:00      
                        nibble-wise?            01/01/70 00:00      
                     nope nope            01/01/70 00:00      
                        noipe, nope, nope            01/01/70 00:00      
                            noipe, nope, nope, nope            01/01/70 00:00      
                              Ok, Ok. Ok, OK            01/01/70 00:00      
                                 max.255 entries - or the tricks :-)            01/01/70 00:00      
                                    the value of verification            01/01/70 00:00      
                  Mirrored tracks            01/01/70 00:00      
                     Why ?            01/01/70 00:00      
                        Working fine            01/01/70 00:00      
                           why you post wrong code ?            01/01/70 00:00      
                              Yes. Code has bug - Peter            01/01/70 00:00      
                                 efficiency            01/01/70 00:00      
                                    Obvious Vs Smart code            01/01/70 00:00      
                                       sorry            01/01/70 00:00      
                                          No offence - only learning            01/01/70 00:00      
   One byte-reversing solution            01/01/70 00:00      
   Byte Bit Reversal            01/01/70 00:00      
      Re: Byte Bit Reversal            01/01/70 00:00      
   Bit Addressing solution!            01/01/70 00:00      
      Hardware?            01/01/70 00:00      
      2 byte of ram or 2 port?            01/01/70 00:00      
   Three ways:            01/01/70 00:00      
      Three (smart) ways            01/01/70 00:00      
      Thanks, Peter, but...            01/01/70 00:00      
         its faster            01/01/70 00:00      
   Topic has been discussed before            01/01/70 00:00      
   You could try a CPLD            01/01/70 00:00      

Back to Subject List