Assembly (emu8086) not allowing moving of bytes into 8-bit registers

淺唱寂寞╮ 提交于 2019-12-11 10:39:35

问题


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

and at the end of the code I have num1 set up as a byte with

num1 db 0

giving it a default value of 0.

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

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.


回答1:


This:

mov offset num1, al

should be:

mov num1, al

And:

mov bl, offset num1

should be:

mov bl, num1

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).

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.



来源:https://stackoverflow.com/questions/31066039/assembly-emu8086-not-allowing-moving-of-bytes-into-8-bit-registers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!