What could be the fastest way to increment two combined bytes in assembler (assuming I'm working on a 8-bit CPU)? Currently I'm doing this:
OVF1_handler: ; TIMER1 overflow ISR lds r21, timerhl ; load low byte into working register; 2 cycles add r21, counter_inc ; add 1 to working register (value of counter_inc is 1); 1 cycle brbs 0, OVF1_handler_carry ; branch if bit 0 (carry flag bit) of SREG is set; 1 cycle if false . 2 cycles if true sts timerhl, r21 ; otherwise write value back to variable; 2 cycles reti ; we're done OVF1_handler_carry: ; in case of carry bit is set sts timerhl, r21 ; write value of low byte back to variable; 2 cycles lds r21, timerhh ; load high byte into working register; 2 cycles inc r21 ; increment it by 1 (no carry check needed here); 1 cycle sts timerhh, r21 ; write value of high byte back to variable; 2 cycles reti ; we're done
So in sum there are
255 * (2+1+1+2) + (2+1+2+2+2+1+2) = 1542 cycles
to count from 0 to 256 (255 times (2+1+1+2) because no overflow plus 1 time (2+1+2+2+2+1+2) when overflow occurs).
Is my calculation correct and is there a faster way?