div6 was prototyped with this program:
typedef unsigned char u8;
int main(void) {
for (int i = 0; i <= 0x78; i++) {
u8 real = i/6;
u8 test = i;
test >>= 1;
test += i;
test >>= 1;
test += 0;
test >>= 1;
test += i;
test >>= 1;
test += 0;
test >>= 1;
test += i;
test >>= 1;
test += 0;
test >>= 1;
test >>= 1;
if (test != real)
printf ("%hhd/6 == %hhd != %hhd\n", i, real, test);
}
return 0;
}
MOV (tmp_1, acc) // acc saved in tmp_1; fresh acc
MOV (acc, i2)
// shift-divide by six
MOV (tmp_1, acc) // acc saved in tmp_1; fresh acc
MOV (acc, i2)
// shift-divide by six
- // note: i2 is max 0x78; so acc will <= 20.
-
+ // note: i2 is max 0x78; so acc will <= 20. (breaks vor values >=128)
// end divide by six
AND (acc, tmp_1) // acc restored from tmp_1
AND (acc, 3)
// end divide by six
AND (acc, tmp_1) // acc restored from tmp_1
AND (acc, 3)