ineedahero
ineedahero

Reputation: 755

Does movsx imply anything about the signed-ness of the destination?

From this question:

movzx ecx, al ; move byte to doubleword, zero-extension

There's also MOVSX if you want the value in al to be treated as signed.

Above, it is mentioned that 'movsx' would imply that al is signed.

  1. Does movzx imply that al is not signed?
  2. What does movsx imply about the signed-ness of ecx (if anything)?
  3. And what does movzx imply about the signed-ness of ecx (if anything)?

Upvotes: 1

Views: 941

Answers (1)

Uprooted
Uprooted

Reputation: 971

There's no signedness per se attached to registers. movsx means "assign destination a value that (being treated as signed) will be equal to a value of source (being treated as signed)". Same for movzx, with unsigned instead signed. So if you use sx it acts as if both source and destination are signed, and zx as if both are unsigned. Example:

let al = 0xFF = (signed) -1 = (unsigned) 255 (the same number, all bits set)

after movsx ecx, al, all bits will be set:
ecx = 0xFFFFFFFF = (signed) -1 = (unsigned) 4294967295

after movzx ecx, al, only lower 8 bits will be set:
ecx = 0x000000FF = (signed) 255 = (unsigned) 255

Note that for smaller register al numbers -1 and 255 are represented by the same set of bits, but for larger register ecx those two same numbers have different bit representation.

Edit: As Jester pointed out, using movzx doesn't imply the signedness of destination, because after movzx destination's highest bit is always 0, so it has the same value both when treated as signed and when treated as unsigned.

Upvotes: 2

Related Questions