Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Write a program that, taken two vectors of 4 word, everyone as matrix row and matrix column, computes the product.
- ;Remember that
- ;if x=(x1, x2, …, xn) and y=(y1, y2, …, yn) are two vectors with n elements, the product between vector column x and vector row y coincides with the matrix of n*n order where the element of ij index is given by product between the i-th component of x and j-th component of y. In formulas:
- ; (x1) (x1y1 x1y2 ... x1yn)
- ; (x2) (x2y1 x2y2 ... x2yn)
- ; (..) * (y1 y2 ... yn) = (... ... ... ... )
- ; (xn) (xny1 xny2 ... xnyn)
- ;IMPLEMENTATION
- ;-For the product you need of a matrix: let's use the base indexed addressing
- ;-Examples:
- ; displacement[BX][DI] displacement[BX][SI]
- ; displacement[BP][DI] displacement[BP][SI]
- ; [BX][DI] [BX][SI]
- ; [BP][DI] [BP][SI]
- ;-Let's store the matrix by rows, on WORD
- ;-matrix[x][y] = matrix[BX][SI], with
- ; –x belonging to [1, NUM_ROW] y [1, NUM_COL]
- ; –BX = (x-1)*2*NUM_COL SI = (y-1)*2
- ;8086 ADDRESSING
- ;-The following representation summarizes all 17 possible ways about 8086 Addressing:
- ; | BX | SI
- ; disp| |
- ; | BP | DI
- ;-Examples:
- ; [BX][SI], [DI], disp, disp[DI], disp[BX][DI]…
- ;-N.B.: when [BP] is used, the processor accesses to stack segment (data segment in all other cases)
- DIM EQU 4
- .MODEL small
- .STACK
- .DATA
- vett1 DW DIM DUP (2)
- vett2 DW DIM DUP (2)
- matr DW DIM*DIM DUP ?
- .CODE
- .STARTUP
- MOV BX,0
- MOV SI,0
- MOV DI,0
- ciclo1:
- MOV CL,BYTE PTR vett1[SI]
- ciclo2:
- MOV AL,BYTE PTR vett2[DI]
- MUL CL
- MOV matr[BX][DI],AX
- ADD DI,2
- CMP DI,DIM*2
- JNE ciclo2
- ADD BX,2
- ADD SI,2
- MOV DI,0
- CMP BX,DIM*2
- JNE ciclo1
- MOV AH,2
- MOV BX,0
- MOV DI,0
- print1:
- print2:
- MOV DL,BYTE PTR matr[BX][DI]
- ADD DL,'0'
- INT 21h
- ADD DI,2
- CMP DI,DIM*2
- JNE print2
- ADD BX,2
- MOV DI,0
- CMP BX,DIM*2
- JNE print1
- ;The print prints well until there are numbers
- ;below 9 due to problem linked
- ;to ASCII code, that reaches up to 9.
- ;If I have numbers that are above 9, it prints other characters
- .EXIT
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement