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.
This:
should be:
And:
should be:
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 useINT 21H / AH=09H
to print a string you needDX
to hold the offset of the string to print, so you would usemov 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 usenum1
(or[num1]
, which means the same thing asnum1
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
orbl
you wouldn't be able to do so.