I used your nice program for making some tests for a clone of Intel microprocessor. I found that the instruction "imul", the ternary variant, sometimes puts incorrect values into the flags.
Example:
1mov si, 7fffh 2imul dx, si, 1
DOSBox sets carry flag and overflow flag (CF = 1, OF = 1), while we must have CF = 0 and OF = 0 according to the logic of Intel.
Well, bug report generated, thanks for paying attention!
Should the res<32767 and res<2147483647 be less than or equal?... or the constants greater by one, but that could flip the sign bit depending on the data size.
According to the logic of the intel docs or the real processors?
The question is interesting. Of course, when we run the example on a real processor, we have CF = OF = 0. But if we look through the official documentation of Intel 80186, where this instruction appeared first... There are two tables there: a table of the strict instruction descriptions and the table of the instruction codes. We find this instruction in the second table (though they don't describe there the code of the variant when the second operand is a pointer to memory). But they don't describe it in the first table! Did they forget to do this, or maybe they didn't do it on purpose?.. Or I just saw a wrong paper? Does not clear.
But, in any case:
1if ((res> -32768) && (res<32767))
Of course, there must be
1if ((res>= -32768) && (res<=32767))
Because in my example we have 32767 as the result, and this is not overflow. And, analogously: