Advertisement
Il_Voza

3.2 Product between 2 vectors and result into a matrix

May 12th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Write a program that, taken two vectors of 4 word, everyone as matrix row and matrix column, computes the product.
  2. ;Remember that
  3. ;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:
  4.  
  5. ;   (x1)                        (x1y1  x1y2  ...  x1yn)
  6. ;   (x2)                        (x2y1  x2y2  ...  x2yn)
  7. ;   (..)  *  (y1 y2 ... yn) =   (...   ...   ...  ... )
  8. ;   (xn)                        (xny1  xny2  ...  xnyn)
  9.  
  10. ;IMPLEMENTATION
  11. ;-For the product you need of a matrix: let's use the base indexed addressing
  12. ;-Examples:
  13. ; displacement[BX][DI]        displacement[BX][SI]
  14. ; displacement[BP][DI]        displacement[BP][SI]
  15. ; [BX][DI]                    [BX][SI]
  16. ; [BP][DI]                    [BP][SI]
  17.  
  18. ;-Let's store the matrix by rows, on WORD
  19. ;-matrix[x][y] = matrix[BX][SI], with
  20. ;  –x belonging to [1, NUM_ROW] y  [1, NUM_COL]
  21. ;  –BX = (x-1)*2*NUM_COL SI = (y-1)*2
  22.  
  23. ;8086 ADDRESSING
  24. ;-The following representation summarizes all 17 possible ways about 8086 Addressing:
  25. ;         | BX | SI
  26. ;     disp|    |
  27. ;         | BP | DI
  28. ;-Examples:
  29. ;  [BX][SI], [DI], disp, disp[DI], disp[BX][DI]…
  30. ;-N.B.: when [BP] is used, the processor accesses to stack segment (data segment in all other cases)
  31.  
  32. DIM EQU 4
  33. .MODEL small
  34. .STACK
  35. .DATA
  36. vett1 DW DIM DUP (2)
  37. vett2 DW DIM DUP (2)
  38. matr DW DIM*DIM DUP ?
  39. .CODE
  40. .STARTUP
  41. MOV BX,0
  42. MOV SI,0
  43. MOV DI,0
  44.  
  45. ciclo1:
  46.        MOV CL,BYTE PTR vett1[SI]
  47.        ciclo2:
  48.               MOV AL,BYTE PTR vett2[DI]
  49.               MUL CL
  50.               MOV matr[BX][DI],AX
  51.               ADD DI,2
  52.               CMP DI,DIM*2
  53.               JNE ciclo2
  54.        ADD BX,2
  55.        ADD SI,2
  56.        MOV DI,0
  57.        CMP BX,DIM*2
  58.        JNE ciclo1
  59. MOV AH,2
  60. MOV BX,0
  61. MOV DI,0
  62. print1:
  63.        print2:
  64.               MOV DL,BYTE PTR matr[BX][DI]
  65.               ADD DL,'0'
  66.               INT 21h
  67.               ADD DI,2
  68.               CMP DI,DIM*2
  69.               JNE print2
  70.        ADD BX,2
  71.        MOV DI,0
  72.        CMP BX,DIM*2
  73.        JNE print1
  74. ;The print prints well until there are numbers
  75. ;below 9 due to problem linked
  76. ;to ASCII code, that reaches up to 9.
  77. ;If I have numbers that are above 9, it prints other characters
  78.        
  79.        
  80.  
  81. .EXIT
  82. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement