Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

assembly - Assembler Programming - Moving content of 32 bit register to a 16 bit register?

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...