Multiplication of int8_t by uint8_t (and vice vers) is broken on Z80.
To see the bug remove the first #ifndef SDCC_z80 in the regression test support/regression/tests/onebyte.c
sdcc generates a call to the multiplication function for int8_t x int8_t, so the unsigned number is treated as a signed number which gives wrong results if it's greater than 127.
Philipp
Logged In: YES
user_id=564030
Originator: YES
While Inoticed this problem in the Z80 port it probably affects all ports that use support functions for 8-bit multiplication: There are just two multiplication support functions: One for signed, one for unsigned multiplication. The one for signed multiplication is used for mixed multiplications, too, which gives wrong results.
I suggest the following fix:
Promote operands of mixed char multiplications to int, do an int multiplication. This is slower, but gives the correct result and I expect mixed char multiplications through support functions to be rare anyway.
Philipp
Logged In: YES
user_id=888171
Originator: NO
Using either the signed or unsigned 8 bit multiplication for mixed operands can only give the wrong result if the result is 16 bits. If the result is only 8 bits it doesn't matter. See also genMultOneByte() in mcs51/gen.c.
Maarten
Fixed in SDCC 2.8.4 #5241.