Bahasa Assembler :
Arrays
|
Arrays dapat diibaratkan sebuah rantai dari sebuah variable. A text string is an example of a byte array, each
character is presented as an ASCII code value (0..255).
Here are
some array definition examples:
a DB 48h, 65h,
6Ch, 6Ch, 6Fh, 00h b DB 'Hello', 0
b is an exact
copy of the a array, when compiler sees a string inside quotes it
automatically converts it to set of bytes. This chart shows a part of the
memory where these arrays are declared:
You can access
the value of any element in array using square brackets, for
example: MOV AL, a[3]
You can also
use any of the memory index registers BX, SI, DI, BP, for
example: MOV SI, 3 MOV AL,
a[SI]
If you need to declare a large array you can use
DUP operator. The syntax for DUP:
number DUP ( value(s) )
number - number of duplicate to make (any constant
value). value - expression that DUP will duplicate.
for
example: c DB 5 DUP(9) is an alternative
way of declaring: c DB 9, 9, 9, 9, 9
one more example: d DB 5 DUP(1, 2)
is an alternative way of declaring: d DB
1, 2, 1, 2, 1, 2, 1, 2, 1, 2
Of course, you can use
DW instead of DB if it's required to keep values larger then
255, or smaller then -128. DW cannot be used to declare strings!
The expansion of DUP operand should not be over 1020
characters! (the expansion of last example is 13 chars), if you need to
declare huge array divide declaration it in two lines (you will get a
single huge array in the memory).
|