Search code examples
assemblyx86tasm

move the values from data segment via offset


I have data segment

dataseg segment para 'data'
var1 db 3 
var2 db 5 
dataseg ends

i'm trying to move the values, i.e.

mov ax, offset var2
mov bx, [ax]

but it doesnt work


Solution

  • In 16-bit real mode, ax is not allowed to be used between brackets (as a base register), but bx is:

    mov bx, offset var2  ;◄■■ BX INSTEAD OF AX.
    mov ax, [bx]
    

    Only bx and bp can be used in this way as base registers when addressing memory. ax is generally used to store/accumulate values for other purposes.

    By the way, your variables are size "byte", but you are moving their value into a size "word" register. You can fix it in two ways:

    var1 DW 3     ;◄■■ USE A WORD SIZE VARIABLE.
    

    or

    mov al, [bx]  ;◄■■ USE A BYTE SIZE REGISTER.