1 / 7

Two Dimensional Arrays

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.

Télécharger la présentation

Two Dimensional Arrays

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Two Dimensional Arrays Two operand types, base-index and base-index-displacement, work well when dealing with two-dimensional arrays.

  2. 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) .data array WORD 1000h, 2000h, 3000h .code mov ebx, OFFSET array mov esi, 2 mov ax, [bx + si] ;ax = 2000h

  3. 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

  4. 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.

  5. 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

  6. 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

More Related