Hey,
Can anybody explain me? -
CX is 16 bit register so maximal value should be 0FFFFh - 65535. How is it possible then, when I:
mov cx, 0FFFFFFFFh
Compiler throws no warings, and no errors but looking on the code in codeview and debug.exe(16 bit debuger, thats why i think) gives FFFF in cx?
It looks like MASM is interpreting the value as -1. Both of these statements:
mov cx, 0ffffffffh
mov cx, -1
Generate the same code:
66B9FFFF mov cx,0FFFFh
Yea, i wrote 32bit program and debuged in Olly and if I give maximum value for ECX 0FFFFFFFFh i got -1 in debugger but good value in registry...I wanna ask why, compiler which always throws up code like this:
mov ah, cx
Does not throw code i maximum value is reached. Its only error if I give value more than 32bit for example 0FFFFFFFF1 then its invalid instrction operands but why it does not warn when I move 32 bit directly into 16 register? Strange...
Yes, it is a "normal" bug.
It it valid to say mov cx,-1 and it so "happens" that -1 binary representation in 2's complement on 32 bits is 0xFFFF_FFFF.
Although logically different for humans the two values are the same for a computer.
The assembler should have kept track of the number of characters in the source code number in order to avoid this.
Besides who is using 16 bits and CX register in our days anymore anyway :P ?
Although a compiler can generate and expose a lot of errors it is not possible to protect yourself from yourself only based on compiler "intelligence". Know your tools and be prudent.