Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another question. the .data section 2

Status
Not open for further replies.

SmileeTiger

Programmer
Mar 13, 2000
200
0
0
US
Hi I now want to take a piece of data that is defined in the .data section of a program and place it in cx. Below is what I am trying..
title display (hello.asm)
.model small
.stack 100h
.data
abc dw 0002h
arrayi dw 00A4h, 00A6h, 00A8h, 00AAh

.code
main proc
;this section puts the initial nibble on the screen
mov ax, 0B800h ; Location for the display
mov ds,ax ; Moves the ax val to the data segment
mov ax, @data
mov es,ax ; Moves the ax val to the data segment
mov ax, 0107h ;Sets the character to a blue dot
mov di, offset arrayi
mov cx,abc <-- this is the important line
StartDraw:
mov bx,es:[di]
mov [bx],ax
add di,2
loop StartDraw

mov ax,4C00h
int 21h
main endp


Why doesn't this work?
 
CX doesn't load properly,
coz, the instrn &quot;mov cx,abc&quot; uses &quot;ds&quot; reigster
by default to get the value of &quot;abc&quot;.
Since u have made ds point to 0b800h,
u r getting a wrong value loaded. The effective
address generated by the processor = b800: (offset value of abc , which is
0 in ur program )

So for any memory reference in ur .data,
use &quot;es&quot;. Coz, u have initialized &quot;es&quot; to point ur
data segment.
For exp, use &quot;mov cx, es:abc&quot; -> Only this intrn,
will fetch u the correct value from the correct segment.

Note:
In real mode, the processor uses a segment and an
offset register to generate an effective address.
In a typical assembly instrn like &quot;mov cx,abc&quot; => u
specify only the offset value. The assembler assumes
that u prefer to use &quot;ds&quot; by default. ( Thats the
necessity for the &quot;assume&quot; directive ). But u can
always override the &quot;segment&quot; prefix. But there
are always some exceptions.
For exp u can't use &quot;mov abc,ss:[sp]&quot;. rather u can
use &quot;mov abc, ss:[bp]&quot;. These are H/W restrictions and
cant b avoided.

Hope it helps u.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top