汇编程序编程-将32位寄存器的内容移动到16位寄存器? [英] Assembler Programming - Moving content of 32 bit register to a 16 bit register?
问题描述
是否可以执行以下操作:MOV AX,EBX
Is it possible to do something like: MOV AX, EBX
如果是的话,在这种情况下会发生什么?
and if yes what happens in such as case?
另外,MOV EBX,AX会发生什么?
Also what happens for: MOV EBX, AX?
(使用NASM,8086架构)
(Using NASM, 8086 architecture)
推荐答案
假定Intel语法,其中
Assuming Intel syntax, where
MOV AX, EBX
如果允许,会将EBX的内容复制到AX.
if allowed, would copy the contents of EBX to AX.
只需尝试一下.我记得它不受支持.但是您可以复制任何16位组,例如
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.
如果AX表示无符号整数,则只需清除EBX并复制到下半部分,例如
If AX represent an unsigned integer, just clear EBX and copy into the lower half, e.g.
XOR EBX, EBX
MOV BX, AX
但是,如果AX表示有符号整数(二进制补码),则需要在整个16个高位中一直复制符号位,这称为符号扩展.
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.
谷歌搜索"x86标志扩展名"给了我
Googling "x86 sign extension" gave me
MOVS EBX, AX
但是我还没有尝试过(也就是说,我现在还没有尝试过,但是20年前我还不知道).
but I haven't tried it (that is, I haven't tried it now, but perhaps 20 years ago, I don't know).
简而言之,咨询文档并试用.
这篇关于汇编程序编程-将32位寄存器的内容移动到16位寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!