Mike Rice schreef op 2013-03-31 23:05:

+__SREG__ = 0x3f
+__tmp_reg__ = 0
+__zero_reg__ = 1
+
+    .global    system_tick_i
+       .type   system_tick_i, @function
+system_tick_i:
+       push r1
+       push r0
+       in r0,__SREG__
+       push r0
+       clr __zero_reg__
+       push r24
+       push r25
+       push r26
+       push r27
+       lds r24,__system_time
+       lds r25,__system_time+1
+       lds r26,__system_time+2
+       lds r27,__system_time+3
+       adiw r24,1
+       adc r26,__zero_reg__
+       adc r27,__zero_reg__
+       sts __system_time,r24
+       sts __system_time+1,r25
+       sts __system_time+2,r26
+       sts __system_time+3,r27
+       pop r27
+       pop r26
+       pop r25
+       pop r24
+       pop r0
+       out __SREG__,r0
+       pop r0
+       pop r1
+       ret
+       .size   system_tick_i, .-system_tick_i


I came up with this:

        push r24

        lds r24,__system_time+0
        subi r24, (-1)
        sts __system_time+0,r24

        lds r24,__system_time+1
        sbci r24, (-1)
        sts __system_time+1,r24

        lds r24,__system_time+2
        sbci r24, (-1)
        sts __system_time+2,r24

        lds r24,__system_time+3
        sbci r24, (-1)
        sts __system_time+3,r24

        pop r24
        ret

Which is much less code, less stack, less cpu cycles.
The last two are nice for an interrupt.

HTH

Wouter

_______________________________________________
AVR-libc-dev mailing list
AVR-libc-dev@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev

Reply via email to