Reputation: 1
I've just started learning Assembly (I got the basis) but I don't know how to switch between data segments. Here's and example :
FRASE DB 'Inserisci un numero : ','$'
DATA ENstrong textDS
DATA2 SEGMENT PUBLIC 'DATA'
VET DB 20 DUP (?)
DATA2 ENDS
CSEG SEGMENT PUBLIC 'CODE'
ASSUME CS:CSEG, DS:DATA
MAIN PROC FAR
MOV AX,SEG DATA
MOV DS,AX
MOV DI,SEG DATA2
XOR AX,AX
MOV CX,20
MOV DX,0
LEA SI,VET
VETTORE :
MOV AH,0
INT 16H
ADD SI,DX
MOV [SI],AL
INC DX
LOOP VETTORE
MOV AH,4CH
INT 21H**
I've used emu8086 to check how does the memory works and I got this results. The program creates the data segment and stores the offset of the var FRASE.
After this, I save another data segment in the DI register. Then, I ask the user to enter a number and here's the problem : when it saves the number in AL and then I copy it in the [SI] memory address, it copies it in the first data segment.
I try to explain better, first data has 0712 address, the second has 0712, I want to save the number in 0712:0000, not in 0710:0000 (where it overwrites the variable FRASE).
Upvotes: 0
Views: 783
Reputation: 58695
Putting the other segment address into the DI register doesn't do anything, since the machine doesn't look for it there. References to memory are always taken with respect to the segment whose address is stored in one of the segment registers CS, DS, ES, SS. For MOV with an [SI] reference, DS is used by default unless you use an override prefix.
If you want to keep using DS for stuff in the DATA segment, then ES is the most reasonable choice. So you could write
MOV DI, DATA2
MOV ES, DI
MOV [ES:SI], AL
Upvotes: 3