two dimensional arrays
DESCRIPTION
Two Dimensional Arrays. Two operand types, base-index and base-index-displacement, work well when dealing with two-dimensional arrays. Base-Index Operands. Adds the values of two registers (base and index), producing an offset address. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Two Dimensional Arrays](https://reader035.vdocuments.us/reader035/viewer/2022072013/56812b0b550346895d8ef275/html5/thumbnails/1.jpg)
Two Dimensional Arrays
Two operand types, base-index and base-index-displacement, work well when dealing with two-dimensional arrays.
![Page 2: Two Dimensional Arrays](https://reader035.vdocuments.us/reader035/viewer/2022072013/56812b0b550346895d8ef275/html5/thumbnails/2.jpg)
Base-Index Operands
• Adds the values of two registers (base and index), producing an offset address.
• Any two general purpose registers may be used in 32-bit mode(in 16-bit mode, only bx with di or si, and bp with di or si)
.dataarray WORD 1000h, 2000h, 3000h.code
mov ebx, OFFSET arraymov esi, 2mov ax, [bx + si] ;ax = 2000h
![Page 3: Two Dimensional Arrays](https://reader035.vdocuments.us/reader035/viewer/2022072013/56812b0b550346895d8ef275/html5/thumbnails/3.jpg)
Table Example
• For two dimensional tables, a base register usually contains a row offset, and an index register contains a column offset.
• Defining a table that has three rows and five columns:
tableB BYTE 10h, 20h, 30h, 40h, 50h
BYTE 60h, 70h, 80h, 90h, 0A0h
BYTE 0B0h, 0C0h,0D0h, 0E0h, 0F0h
NumCols = 5
![Page 4: Two Dimensional Arrays](https://reader035.vdocuments.us/reader035/viewer/2022072013/56812b0b550346895d8ef275/html5/thumbnails/4.jpg)
Memory
• In memory this table is a continuous stram of bytes as if it were a one-dimensional array.
• The physical storage of the array is in row-major order, where the last byte in the first row is followed by the first byte in the second row, and so on.
![Page 5: Two Dimensional Arrays](https://reader035.vdocuments.us/reader035/viewer/2022072013/56812b0b550346895d8ef275/html5/thumbnails/5.jpg)
How to move through the tableAssuming that the rows begin with 0, Columns begin with 0.
RowNumber = 1
Column Number =2
Mov ebx, OFFSET tableB
Add ebx, NumCols * RowNumber
Mov esi, ColumnNumber
Mov al, [ebx + esi] ;AL = 80h
![Page 6: Two Dimensional Arrays](https://reader035.vdocuments.us/reader035/viewer/2022072013/56812b0b550346895d8ef275/html5/thumbnails/6.jpg)
150 155 15710 20 30 40 50 60 70 80 90 A0 B0 C0 D0 E0 F0
[ebx] [ebx + si]
![Page 7: Two Dimensional Arrays](https://reader035.vdocuments.us/reader035/viewer/2022072013/56812b0b550346895d8ef275/html5/thumbnails/7.jpg)
Looking at Memory Locations• Move into BX, OFFSET of tableB• Each row is 5 bytes long (NumCols)• Data is on 1st row (row nums begins with 0)• Multiply Rownumber * NumCols• Add result to bx.• Move into SI, ColumnNumber (data is in 2nd
column)• Move into al, value
150 155 15710 20 30 40 50 60 70 80 90 A0 B0 C0 D0 E0 F0
[ebx] [ebx + si]