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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/05/05 10:49
Read: times


 
#104694 - optimizing further
Responding to: ???'s previous message
Peter,

your routine assumes 1 BCD digit per "occurence", this is the most common case when you e.g. receive digits via UART (in ASCII form, so first you need to convert from ASCII into BCD). However, my task was to convert packed BCD, i.e. 2 digits per "occurence"; hence the multiply by 100 (it is less than 256 so the routine itself is the same). My "less efficient" algorithm is written almost the same as yours, except it is for the "2 digits per occurence" and is explicitly unrolled - code space inefficient, but faster. Of course, optimisation is often a balancing act between the resources...

But sometimes one does not need to make compromises and the optimisation can save all the resources. For example, let me optimize your routine a little bit, saving some 1 cycle, 1 code byte and 1 register :-)
amula10:
        mov     r2, #4          ;4 byte value
_amu1:
                   ;digit to add in acc
        xch     a, @r0
        mov     b, #10
        mul     ab              ;* 10
        add     a, @r0           ;add digit or carry
        mov     @r0, a
        clr     a
        addc    a, b            ;add carry
        inc     r0              ;next byte
        djnz    r2, _amu1
        ret

Have fun!

Jan Waclawek


List of 30 messages in thread
TopicAuthorDate
week puzzle V            01/01/70 00:00      
   that would be intersating only to codebr            01/01/70 00:00      
      codebreakers            01/01/70 00:00      
         busted            01/01/70 00:00      
   having a guess            01/01/70 00:00      
   Hmm,isn't it demotivating to reengineer?            01/01/70 00:00      
      Cool algorithm            01/01/70 00:00      
      maybe            01/01/70 00:00      
   Looks like BCD to binary routine            01/01/70 00:00      
   My assumption            01/01/70 00:00      
   The source with comments !            01/01/70 00:00      
      thanks            01/01/70 00:00      
         Seems more elegant ...            01/01/70 00:00      
            optimized=ugly            01/01/70 00:00      
         why "xrl a,#0F0h" ?            01/01/70 00:00      
            Wow!            01/01/70 00:00      
         A bit shorter ...            01/01/70 00:00      
            za Slobodana Mandarica            01/01/70 00:00      
      another approach            01/01/70 00:00      
         optimizing further            01/01/70 00:00      
            packed bcd            01/01/70 00:00      
               packed bcd... by specification :-)            01/01/70 00:00      
      that is not comments, that is "explanati            01/01/70 00:00      
         true if            01/01/70 00:00      
         Yes they are Comments            01/01/70 00:00      
            Exactly !            01/01/70 00:00      
            I have seen such called "comments" way t            01/01/70 00:00      
               more on comments            01/01/70 00:00      
                  the point            01/01/70 00:00      
                     "anyone" and the point            01/01/70 00:00      

Back to Subject List