From 7cbbb5ba36f91d988768b2e49799663e3aef4bef Mon Sep 17 00:00:00 2001 From: Tobias Girstmair Date: Thu, 4 Mar 2021 13:41:18 +0100 Subject: [PATCH] new version 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; } --- bsv.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/bsv.c b/bsv.c index 8ce4b42..8bbde09 100644 --- a/bsv.c +++ b/bsv.c @@ -95,9 +95,37 @@ void main(void){ 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) -- 2.39.3