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

putting data into array

Status
Not open for further replies.

glogic

Programmer
Nov 8, 2001
15
0
0
IE
in assembly language how do i place numbers into an array

numarray db 5 dup(?)
firstnum db 0

mov ah,1
int 21h
mov firstnum,al
mov bx,offset numarray
mov [bx],firstnum

now i aint sure if a variable can be placed into an array like this.. does it have to come from a register like al?
if i wanted to take in 5 numbers how do i move through the array to place them in? do i just inc bx ?

 
Let's do a bit of a review. the mov instruction can transfer:
register to register
register to memory
memory to register
constant to register
constant to memory
register to segment register
segment register to register
memory to segment register
segment register to memory

There is NO mov instruction that can transfer memory-to-memory. mov [bx],firstnum IS NOT LEGAL because [bx] refers to a memory address (the memory address of the array) and firstnum refers to another memory address (the firstnum variable)

HOWEVER:
between mov bx,offset numarray and your attempted mov [bx],firstnum, al is NOT changed, which means you can do:
mov firstnum,al
mov bx,offset numarray
mov [bx],al

"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
so if i wanted to put another variable in the next position do i increment bx?
inc bx

also if i want bx to point to the first postion of the array do i
mov bx,'0'
to repostion it at the start?
or
mov bx,offset numarray
again


i just want to thank u have been a great help..
 
its ok i figured this one out.. thanks again AmkG
 
mov bx, offset numarray

and

inc bx

are correct

NOTE!

if you use a word array:
numarray dw n dup (0)

make sure to consider the SIZE of each element when you increment/decrement bx!

i.e. words are two bytes long, so instead of inc bx, do add bx,2. If your array elements are three bytes long, use add bx,3... etc.

Just a reminder! "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top