12 #define x r26 //==Xlo==Mh
13 #define t r27 //==Xhi==Ml
21 #define Mh r26 //mod3 vars
39 .byte 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58
40 .byte 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
44 mod3: ; mod3(Mh.Ml) -> t
73 ; definitions to mul-tree readable:
74 .macro always _bit ; nop; for when a test() is not necessary (see tree)
76 .macro never _bit ; nop; for when a test() is not necessary (see tree)
78 .macro test _bit,_jmpto
86 .macro shift8 ; top three bits don't need to be corrrect, so save cycles by not carrying
89 .macro shift0 ; nop; last shift is common
96 .macro add_shift8 ; ditto with carrying
100 .macro add_shift0 ; last shift is common
115 MOV tmp, t ; NOTE: must move value away from `t`, as that is also hi(X)
116 LDI Xhi, hi8(data) ; TODO: can skip if &data < 0xff (it is)
118 ADD Xlo, tmp ;<-- the offset (formerly `t`) into data[]
119 ADC Xhi, zero ; ditto skip
130 /* decision tree multiplication saves cycles and (hopefully) reduces code size
137 _?000 _?100 _?001 _?101
139 _0000 _1000 _0100 _1100 _1001 _0101 _1101
141 ... ... ... ... ... ... ...
143 B0 58 84 8C 69 75 9D */
160 RJMP end_mul ; calc'd 0xb0
171 RJMP end_mul ; calc'd 0x58
176 RJMP upper_8 ;'ll calc 0x84
179 upper_8: ; used twice, so deduplicated
188 RJMP end_mul ; calc'd 0x8c
205 RJMP end_mul ; calc'd 0x69
218 RJMP end_mul ; calc'd 0x75
232 LSR a1 ;final shift is a common operation for all
234 MOV t, a1 ;;TODO: use a1 in main() directly
238 RET ; TODO: replace CALL/RET with IJMP?
246 ;;TODO: setup stack pointer, portb, clock, sleep mode, timer0
248 sample: ;;TODO: this will probably become the timer0 overflow interrupt handler
400 rjmp sample ;;TODO: -> RETI