So:
|
Specifically: be aware that you must obey the memory alignment requirements !!!
See: click here
.byte .2byte .4byte |
that you learned in this webpage: click here
Examples:
|
.skip n // Reserve n consecutive bytes of memory |
that you learned in this webpage: click here
You need to calculate the number of bytes that you need to reserve for the array that you want to define.... (that's pretty easy)
You can use the multiply operator * to compute the number of bytes needed.
Examples:
|
/* -------------------------------------------------- Begin of the permanent program variables -------------------------------------------------- */ .data A: .byte 11, 12, 13, 14, 15 // byte typed initialzied array A a: .skip 10*1 // byte typed UNinitialized array a (10 elements) .align 1 B: .short 111, 112, 113, 114, 115 // short typed initialzied array B b: .skip 10*2 // short typed UNinitialized array b (10 elements) .align 2 C: .short 1111, 1112, 1113, 1114, 1115 // int typed initialzied array C c: .skip 10*4 // int typed UNinitialized array c (10 elements) |
How to run the program:
|
Here's a snapshot of the memory content when you run this program in EGTAPI:
The content of the memory is shown in hexadecimal numbers
Each pair of hexadecimal digit represents the byte stored at that location in memory.
The memory address of the first byte in a line of bytes is given in hexadecimal at the left margin
You can see that the first 5 bytes (0b 0c 0d 0e 0f) is the initialized array A[ ] = 11, 12, 13, 14, 16
Then the next 10 bytes (all 00) is the UNinitialized array a[10] (10 elements)
The next byte (the 00 at the end of line 1) is skipped to comply with the alignment requirement for the B[ ] array:
|
The first 10 bytes on line 2 belong to the initialized short array B:
006f hex = 111 decimal 0070 hex = 112 decimal 0071 hex = 113 decimal 0072 hex = 114 decimal 0073 hex = 115 decimal |
Then the next 20 bytes (all equal to 00) belongs to the unintialized short array b[10]
The next 2 bytes (the 00 00 at the end of line 3) are skipped to comply with the alignment requirement for the C[ ] array:
|
The bytes on line 4 and the first 4 bytes on line 5 belong to the initialized int array C:
00000457 hex = 1111 decimal 00000458 hex = 1112 decimal 00000459 hex = 1113 decimal 0000045a hex = 1114 decimal 0000045b hex = 1115 decimal |
Then the next 40 bytes (all equal to 00) belongs to the unintialized int array c[10]