简体   繁体   中英

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, ie

mov ax, offset var2
mov bx, [ax]

but it doesnt work

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM