Question

Is it possible to do something like: MOV AX, EBX

and if yes what happens in such as case?

Also what happens for: MOV EBX, AX?

(Using NASM, 8086 architecture)

Was it helpful?

Solution

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.

OTHER TIPS

Use mov ax,bx, to move the lower 16 bits of bx into ax.

Use movsx ebx,ax to move ax into ebx with sign extension

Use movzx ebx,ax to move ax into ebx, zeroing the upper 16 bits of ebx.

MOV AX, EBX ... if this will compile the you might get BX in AX.

MOV EBX, AX will get AX in BX and zeroes before it...

I don't have an assembler at my hand right now, but please try and see what happens...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top