1

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)?
phuclv
  • 37,963
  • 15
  • 156
  • 475
ineedahero
  • 715
  • 1
  • 5
  • 10
  • 2
    1) yes 2) signed 3) nothing – Jester Apr 30 '18 at 23:16
  • The signed/unsigned refer to presence or absence of _sign extension_ respectively. That is, `movzx` always fills the top 24 bits of the result with 0's, but `movsx` fills them with a copy of the byte's sign bit (bit 7). – Gene May 01 '18 at 00:20
  • 1
    `al` is 8 bits (eight 0/1 values), nothing more, no sign, type or origin information (the top bit is interpreted as sign, when the value is treated as signed one, but it's same bit as any others, except being "positioned" at top). In the same way `ecx` is 32 bits and nothing more. The signed/unsigned is *interpretation* of those bit values, and the interpretation is done by the code using those bit values, but without the code they are just 8 and 32 bits. As in the example in the answer, 8 bits set to 1111_1111 can be interpreted (among other meanings) either as +255, or as -1. Depends on code – Ped7g May 01 '18 at 06:36

1 Answers1

2

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.

Uprooted
  • 941
  • 8
  • 21
  • 2
    `movzx` does not require destination to be unsigned. If you are extending unsigned byte to signed dword, you use `movzx` too. – Jester May 01 '18 at 00:45