What should happen with bitwise OR with two different variable sizes

Started by kcsl, Jan 31, 2025, 09:49 AM

Previous topic - Next topic

kcsl

I've been going crazy trying to find a bug in my program and I found this.

dim dblOutput     as dword = $700
dim bytValue      as byte  = $FF

    dblOutput = dblOutput | bytValue

I expected dblOutput to be $7FF but it's coming out as $FF

Can probably code around this but which is the correct answer?

Actually, changed it to dblOutput = dblOutput + bytValue and that works, so not a problem for me in this instance.

Regards,
Joe

There's no room for optimism in software or hardware engineering.

top204

That is my mistake in the logic of the code generator. It is reacting it as if only the first 8-bits need to be ORed, so it is clearing the rest of the Dword variable, as it would do if it was an ANDing.

This is a "day one" anomaly, that has been with the compiler since I first added Dword variables about 20 years ago! It also effects the Xor logic.

I am busy correcting them now for the up and coming update.

Thanks for spotting it Joe, and I will check out the other boolean mechanisms for different variable types, where the second operand is a smaller type.

You can do the code:

dblOutput.Byte0 = dblOutput.Byte0 | bytValue

And it will do the correct logic and perform the ORing on the first 8-bits only of dblOutput, and will not be effected by the up and coming correction.