div10 was prototyped with this program:
typedef unsigned char u8;
int main(void) {
for (int i = 0; i <= 0x78; i++) {
u8 real = i/10;
u8 test = i;
i++;
test >>= 1;
test += i;
test >>= 1;
test += 0;
test >>= 1;
test += 0;
test >>= 1;
test += i;
test >>= 1;
test += i;
test >>= 1;
test += 0;
test >>= 1;
test += 0;
test >>= 1;
test += 0;
test >>= 1;
i--;
if (test != real)
printf ("%hhd/10 == %hhd != %hhd\n", i, real, test);
}
return 0;
}
CALL (g)
SR (acc)
MOV (tmp_1, acc) // acc saved in tmp_1; fresh acc
+ MOV (acc, i2)
// shift-divide by ten
// note: i2 is max 0x78; so acc will <= 12.
- acc = i2/10;//TODO
+ i2++;
+ acc >>= 1;
+ acc += i2;
+
+ acc >>= 1;
+ acc += 0;
+
+ acc >>= 1;
+ acc += 0;
+
+ acc >>= 1;
+ acc += i2;
+
+ acc >>= 1;
+ acc += i2;
+
+ acc >>= 1;
+ acc += 0;
+
+ acc >>= 1;
+ acc += 0;
+
+ acc >>= 1;
+ acc += 0;
+
+ acc >>= 1;
+ i2--;
+
// end divide by ten
AND (acc, tmp_1) // acc restored from tmp_1
AND (acc, 3)