问题描述
我想提出一个计算器类型的节目,我用它来从用户那里得到一个数字,并将其存储:
I am making a calculator-type program, and I use this to get a number from the user and store it:
mov ah, 01h
int 21h
mov offset num1, al
和在code结束时,我有NUM1设置为一个字节以
and at the end of the code I have num1 set up as a byte with
num1 db 0
给它的默认值为0。
giving it a default value of 0.
问题是,当我尝试从NUM1值搬回到寄存器来执行实际操作:
The problem is, when I try to move the value from num1 back into a register to perform the actual operation:
mov bl, offset num1
我得到一个错误说第二个操作数是超过8位,我无法通过互联网/手册中的任何搜索摸不着头脑。
I get an error saying the second operand is over 8 bits, and I cannot figure this out through any searching of the internet/manuals.
另外,我使用偏移瓦尔,因为这就是我最初是教他们,我真的不明白他们的任何其他方式。
Also, I use offset vars because that is how I was initially taught them and I don't really understand them any other way.
推荐答案
这
mov offset num1, al
应该是:
mov num1, al
和
mov bl, offset num1
应该是:
mov bl, num1
的偏移
关键字应该在你想要得到一个标签的地址(或它的一个段内的偏移,以precise)的情况下使用。例如,如果你使用 INT 21H / AH = 09H
来打印你需要一个字符串 DX
持有的偏移字符串打印,所以你可以使用 MOV DX,偏移my_string
。结果
但在code你已经证明你在 NUM1
加载和存储的价值有兴趣,所以你只需要使用 NUM1
(或 [NUM1]
,这意味着为 NUM1
在MASM / TASM同样的事情在这种情况下的语法)。
The offset
keyword should be used in situations where you want to get the address of a label (or its offset within a segment, to be precise). For example, if you use INT 21H / AH=09H
to print a string you need DX
to hold the offset of the string to print, so you would use mov dx, offset my_string
.
But in the code you've shown you're just interested in loading and storing the value at num1
, so you should simply use num1
(or [num1]
, which means the same thing as num1
in MASM/TASM syntax in this context).
对于错误信息的含义是:一个在真实模式程序偏移量是16位的,所以即使你真的想将它移动到一个8位寄存器,如人
或 BL
,你就不能这样做。
Regarding the meaning of the error message: an offset in a real-mode program is 16 bits, so even if you really wanted to move it into an 8-bit register like al
or bl
you wouldn't be able to do so.
这篇关于大会(EMU8086)不允许字节移入8位寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!