[Solved] Assembler Programming – Moving content of 32 bit register to a 16 bit register?


Assuming Intel syntax, where

MOV AX, EBX

if allowed, would copy the contents of EBX to AX.

Just try it. As I remember it’s not supported. But you can copy any 16-bit group, e.g.

MOV AX, BX

However, regarding the opposite, extending a bit pattern, like the hypothetical

MOV EBX, AX

how to do that depends on what you want.

If AX represent an unsigned integer, just clear EBX and copy into the lower half, e.g.

XOR EBX, EBX
MOV BX, AX

If however AX represents a signed integer (two’s complement) you need to replicate the sign bit all the way throughout the 16 upper bits, which is called sign extension.

Googling “x86 sign extension” gave me

MOVS EBX, AX

but I haven’t tried it (that is, I haven’t tried it now, but perhaps 20 years ago, I don’t know).

In short, consult the documentation and try it out.

1

solved Assembler Programming – Moving content of 32 bit register to a 16 bit register?