When multiplying a 16 bit signed integer by zero and saving it into a 32 bit signed integer, the compiler (under Qbasic compatibility mode) generates invalid assembly.
Consider the following code:
DEFINT A-Z '16 bit integers in QB mode
DIM B AS LONG '32 BIT INTEGER
B = A * 3
B = A * 0
For the first multiply, the assembly generated is essentially:
mov ax, a
imul ax, 3
movsx eax, ax
mov b, eax
For the second multiply, the compiler realizes that a variable times zero is zero, and so it attempts to skip the multiply by loading a sign-extended 16 bit 0 into the 32bit register:
movsx eax, 0
mov b, eax
But the sign extend opcode does not allow for immediate values (ie, constants), causing the assembler to generate an error:
"Error: suffix or operands invalid for 'movsx' "
Bug in 16 to 32 bit integer conversion
Re: Bug in 16 to 32 bit integer conversion
You have done some excellent work tracking that one down. Can you please post it as a bug report on sourceforge so it won't get lost or forgotten in this forum.
I think the link is http://sourceforge.net/tracker/?group_i ... tid=693196
I think the link is http://sourceforge.net/tracker/?group_i ... tid=693196
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Bug in 16 to 32 bit integer conversion
Wow, not bad for a first post :)
Here's a version in the standard dialect that shows the same effect:EDIT: similar effects for And cshort(0) / Or cshort(-1) (unsurprisingly).
Here's a version in the standard dialect that shows the same effect:
Code: Select all
dim a as short, b as long
b = a * cshort(3)
b = a * cshort(0)
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Bug in 16 to 32 bit integer conversion
Bug reported now. Thanks.
http://www.sf.net/support/tracker.php?aid=3469530
http://www.sf.net/support/tracker.php?aid=3469530
Re: Bug in 16 to 32 bit integer conversion
D'oh! Sorry guys, I didn't see the correct place to post bugs until after I posted this; I felt kinda stupid :P
Thank you, Counting_pine, for correctly reporting it for me.
Thank you, Counting_pine, for correctly reporting it for me.