Last time, I covered the basics of doing multiply and divide
with 8-bit numbers. So far, these routines only worked for
unsigned numbers. This time I will show how to add support for
signed numbers, some ways to extend these routines to numbers of
more than 8 bits, and also some optimizations. Another thing
that I have not mentioned specifically was a compare-operation
for more than 8-bit. For the division you would need one. I will
just start there. Comparing more than 8 bits Let’s say we want
to compare two 16-bit numbers x and y. We can start by just
looking at the high bytes. If high(x) > high(y), then it must
follow that x > y. Likewise, if high(x) < high(y), it follows
that x < y. If high(x) == high(y), then we have to check the low
bytes. In that case, if low(x) < low(y), then x < y, if low(x) >
low(y), then x > y, and if low(x) == low(y), then x == y. So we
could use some code like this: Quite simple, is it not? Once we
have executed this code, the status register reflects the
comparison of x and y ju