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

1.4k views Asked by At

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

There are 1 answers

0
Michael On

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.