Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Faster multiply?
#8
britlion Wrote:
boriel Wrote:Note, your routine returns result in L not in A. Perhaps this routine could be rearranged?

Probably. But how can you expect to be able to hold the result of 8 bit * 8 Bit in an 8 bit register? The result should be in something like HL surely?
That's right. In fact, the old mul8 routine did a * h => DE, returning E. When doing 8bit x 8bit, the compiler returns the result in 8 bit (all are bytes). So if you multiply 2 bytes, you will probably overflow if they're greater than 12 each (12 x 12 = 144). There's a wide range of combinations which do not overflow, though.

The same applies to any other mutiplication (float, fixed, etc...). Most programmers are so used to types that they unconsciously choose the right type when they expect a multiplication (e.g. choose uinteger if they're going to multiply 15 x 15 instead of byte).

When the factors have not the same type, the smallest one is expanded, so 8 x 257 will CAST 8 to Uinteger first.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)