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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array question 1

Status
Not open for further replies.

SmileeTiger

Programmer
Mar 13, 2000
200
US
Hi,

I am trying to use an array as part of my final project for comp arch II however I am running into a little trouble. What I am trying to do is have an array contain the positions of characters on the screen then display a given character at these positions.

Here is my sample code not using the array:
.model small
.stack 100h
.data
.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, 0107h ;Sets the character to a blue dot
mov bx,0A4h ; Starting point
mov [bx],ax
add bx,2
mov [bx],ax
main endp

This outputs 2 blue dots as the 3rd & 4th characters of the second line.
I now want to modify this program to use an array. What I have thus far is as follows:

title display (hello.asm)
.model small
.stack 100h
.data
arrayi dw 00A4h, 00A6h
.code

main proc
call outline
;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, 0107h ;Sets the character to a blue dot
mov di, offset arrayi
mov bx,[di]
mov [bx],ax
add di,2
mov bx,[di]
mov [bx],ax
mov ax,4C00h
int 21h
main endp

Any idea why this doesn't work?

 
It doesn't work because you use the same
segment pointer for array and screen:

mov bx,[di] -> mov bx, ds:[di] -> mov bx, 0B800h:[di]

but it should be

mov bx,[di] -> mov bx, ds:[di] -> mov bx, data:[di]

So, you can modify your example as following:

main proc
call outline
;this section puts the initial nibble on the screen

mov ax, 0B800h ; Location for the display
mov es,ax ; Moves the ax val to the extra data segment

mov ax, @data
mov ds,ax ; Moves the ax val to the data segment

mov ax, 0107h ;Sets the character to a blue dot
mov di, offset arrayi
mov bx,[di]
mov es:[bx],ax
add di,2
mov bx,[di]
mov es:[bx],ax
mov ax,4C00h
int 21h
main endp





 
It doesn't work because you use the same
segment pointer for array and screen:

mov bx,[di] -> mov bx, ds:[di] -> mov bx, 0B800h:[di]

but it should be

mov bx,[di] -> mov bx, ds:[di] -> mov bx, data:[di]

So, you can modify your example as following:

main proc
call outline
;this section puts the initial nibble on the screen

mov ax, 0B800h ; Location for the display
mov es,ax ; Moves the ax val to the extra data segment

mov ax, @data
mov ds,ax ; Moves the ax val to the data segment

mov ax, 0107h ;Sets the character to a blue dot
mov di, offset arrayi
mov bx,[di]
mov es:[bx],ax
add di,2
mov bx,[di]
mov es:[bx],ax
mov ax,4C00h
int 21h
main endp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top