Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
One-dimensional arrays (tables) can be be accessed using Pentium MOV instructions with the appropriate addressing mode Consider a table of five elements containing 5 bytes stored starting at an offset 2000H in DS
An index register such as DI can be initialized with the element number to read an element from this array into a register If (DI) = 2, then MOV CL , [2000H + DI] will load element 2 from offset 2002H into CL If (DI) = 4, then MOV CL,[2000H + DI] transfers element 4 into CL
Suppose that an array of 10 elements containing 32-bit data words is stored starting at an offset 4000H. The following instruction sequence can be used:
Two-Dimensional arrays
Assume a 2 x 3 matrix (two rows and three columns) as shown below Since memory is one-dimensional, this matrix is stored in memory using columnmajor or row-major ordering
Column-Major Ordering
The elements are stored column by column, starting with the first column
Row-Major Ordering
The elements are stored row by row, starting with the first row
Two-Dimensional arrays
Assume that an offset 2000H addresses the first element a[0,0] of the array In the C language, which uses row-major ordering, one can express displacement d of an element at row i and column j as: d=(i*t+j)*s
Where t is the total number of columns and s is the element size (1 for byte, 2 for 16-bit, and 4 for 32-bit) To find the displacement of element a[1 ,0] assuming that each element is 16-bit, the offset can be determined as follows:
i = 1 , j = 0, t = 3 (since 2 x 3 matrix), and s=2 (16-bit element). Hence, d = (1*3 + 0)*2 = 6 Therefore, the offset where element a[1 ,0] is stored = 2000H + 6 = 2006H Hence, the matrix above with row-major ordering can be stored with starting offset 2000H as follows:
Example
Solution
Example
Using string instructions, write a Pentium assembly language program that moves 50 consecutive bytes from offset SOURCE to offset DESTINATION from low to high addresses: Using LOOP instruction Using REP prefix and string instructions
Example
Problem 11.6
Write a Pentium assembly program to move 100 words from a source with offset 0010H in ES to a destination with offset 0100H in the same extra segment
Problem 11.7
Write a Pentium assembly language program to compare two strings of 15 ASCII characters from LOW to HIGH memory The first character (string 1) is stored starting at offset 5000H in DS= 0020H followed by the string. The first character of the second string (string 2) is stored starting at 6000H in ES = 1000H
The ASCII character in the first location of string 1 will be compared with the first ASCII character of string 2, and so on As soon as a match is found, store 00EEH onto the stack; otherwise, store 0000H onto the stack. Initialize SS to 0500H and SP to 2000H
Problem 11.8
Write a Pentium assembly language program to move two columns of 100 32-bit numbers from A (i) at offset 4000H in DS to B (i) at offset 5000H in ES from LOW to HIGH memory In other words, move A (1) to B (1), A (2) to B (2), and so on