News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

cx - 16 bit but 32 bit value mov possible? :O

Started by arcktos, February 21, 2008, 06:12:45 PM

Previous topic - Next topic

arcktos

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?

MichaelW

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
eschew obfuscation

arcktos

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...

BogdanOntanu

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.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro