Advertisement
Guest User

project

a guest
Apr 8th, 2020
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     include 'emu8086.inc'
  2.    
  3.     org     100h
  4.  
  5. main:
  6.     call pthis
  7.     db 'enter the first matrix row by row, and the second matrix column by column: ', 10, 13, 0
  8.     lea si, l1
  9.     call print_string
  10.     lea si, l2
  11.     call print_string
  12.     lea si, l3
  13.     call print_string
  14.     lea si, l4
  15.     call print_string
  16.     lea si, l5
  17.     call print_string
  18.     lea si, l6
  19.     call print_string
  20.     lea si, l7
  21.     call print_string
  22.     lea di, arrayA
  23.     ; first matrix first row
  24.     gotoxy 1, 2
  25.     call scan_num
  26.     mov [di], cl
  27.     inc di
  28.     gotoxy 8, 2
  29.     call scan_num
  30.     mov [di], cl
  31.     inc di
  32.     gotoxy 16, 2
  33.     call scan_num
  34.     mov [di], cl
  35.     inc di  
  36.     ; first matrix second row
  37.     gotoxy 1, 4
  38.     call scan_num
  39.     mov [di], cl
  40.     inc di
  41.     gotoxy 8, 4
  42.     call scan_num
  43.     mov [di], cl
  44.     inc di
  45.     gotoxy 16, 4
  46.     call scan_num
  47.     mov [di], cl
  48.     inc di
  49.     ; first matrix third row
  50.     gotoxy 1, 6
  51.     call scan_num
  52.     mov [di], cl
  53.     inc di
  54.     gotoxy 8, 6
  55.     call scan_num
  56.     mov [di], cl
  57.     inc di
  58.     gotoxy 16, 6
  59.     call scan_num
  60.     mov [di], cl
  61.     inc di
  62.    
  63.     ; second matrix first column
  64.     gotoxy 26, 2
  65.     call scan_num
  66.     mov [di], cl
  67.     inc di
  68.     gotoxy 26, 4
  69.     call scan_num
  70.     mov [di], cl
  71.     inc di
  72.     gotoxy 26, 6
  73.     call scan_num
  74.     mov [di], cl
  75.     inc di
  76.     ; second matrix second column
  77.     gotoxy 32, 2
  78.     call scan_num
  79.     mov [di], cl
  80.     inc di
  81.     gotoxy 32, 4
  82.     call scan_num
  83.     mov [di], cl
  84.     inc di
  85.     gotoxy 32, 6
  86.     call scan_num
  87.     mov [di], cl
  88.     inc di
  89.     ; second matrix third column
  90.     gotoxy 40, 2
  91.     call scan_num
  92.     mov [di], cl
  93.     inc di
  94.     gotoxy 40, 4
  95.     call scan_num
  96.     mov [di], cl
  97.     inc di
  98.     gotoxy 40, 6
  99.     call scan_num
  100.     mov [di], cl
  101.     inc di
  102.     pause
  103.    
  104.    
  105.      
  106.    
  107. menu:  
  108.     call clear_screen
  109.     call pthis
  110.     db 'Select one option from below: ', 10, 13, 0
  111.     call pthis
  112.     db 9, '1- Dot Product.', 10, 13, 0
  113.     call pthis
  114.     db 9, '2- Transpose Matrix A.', 10, 13, 0
  115.     call pthis
  116.     db 9, '3- Transpose Matrix B.', 0
  117.    
  118. inf:
  119.         call pthis
  120.         db  10, 13, 'What is your selection: ', 0
  121.         call scan_num
  122.        
  123. ;        mov ax, cx      
  124. ;        cmp ax, 1
  125. ;        jne nxt1
  126. ;        call CrossProduct
  127.         pause
  128. ;nxt1:        
  129.         cmp ax, 1
  130.         jne nxt2
  131.         call DotProduct
  132.         lea si, DotArray
  133.         call put_num
  134.         pause
  135.        
  136.        
  137. nxt2:   cmp ax, 2
  138.         jne nxt3
  139.         lea si, ArrayA
  140.         lea bx, PosA
  141.         lea di, TransposeA
  142.         call Transpose
  143.         lea si, TransposeA
  144.         call put_num
  145.         pause
  146.        
  147.        
  148. nxt3:    cmp ax, 3
  149.         jne nxt4
  150.         lea si, ArrayB
  151.         lea bx, PosB
  152.         lea di, TransposeB
  153.         call Transpose
  154.         lea si, TransposeB
  155.         call put_num
  156.         pause
  157.        
  158.        
  159.        
  160. nxt4:    jne menu
  161.  
  162. crossProduct    proc
  163.                 call clear_screen
  164.                 ; implement crossProduct    
  165. crossProduct    endp
  166.    
  167. DotProduct  proc
  168.             call clear_screen
  169.            
  170.             ; start Dot product
  171.             push ax
  172.             push bx
  173.             push cx
  174.             push si
  175.             push di
  176.             lea si, ArrayA
  177.             lea bx, ArrayB
  178.             lea di, DotArray
  179.  
  180.  
  181.             mov cx, 3
  182.             col:
  183.             push bx
  184.             push cx
  185.             mov cx, 3
  186.                 row:
  187.                 push cx
  188.                 push si        
  189.                 mov  cx, 3        
  190.                     rowxcol:              
  191.                     mov  al, [si]
  192.                     imul [bx]
  193.                     add  [di], al    
  194.                     inc si
  195.                     inc bx
  196.                     loop rowxcol      
  197.                 pop     si
  198.                 pop     cx      
  199.                 inc     di
  200.                 loop    row
  201.        
  202.             add     si, 3
  203.             pop     cx
  204.             pop     bx
  205.             loop    col
  206.            
  207.             pop di
  208.             pop si
  209.             pop cx
  210.             pop bx
  211.             pop ax
  212.             call put_num
  213.            
  214. DotProduct  endp
  215.  
  216. Transpose   proc
  217.            
  218.            
  219.             ; load into si array
  220.             ; load into bx pos
  221.             ; load into di trans
  222.             push si
  223.             push bx
  224.             push di
  225.             lea si , arraya
  226.             lea di, aux
  227.             nextt:
  228.             mov al, b.[si]
  229.             mov [di], al
  230.             add di, 2
  231.             inc si
  232.             loop nextt
  233.             mov cx, 9
  234.             rot:
  235.                 push di
  236.                 add di, [bx]
  237.                 mov al, [si]
  238.                 mov [di], al
  239.                 pop di
  240.                 add si, 2
  241.                 add bx, 2
  242.                 loop rot
  243.              
  244.            
  245. Transpose   endp
  246. ret
  247.  
  248. PUT_NUM     proc
  249.             ; load the desierd matrix into si
  250.            
  251.             call pthis
  252.             db 218, 9, 9, 9, 191, 13, 10, 179, 0
  253.             printRow
  254.             call pthis
  255.             db 179, 13, 10, 0
  256.             call pthis
  257.             db 179, 9, 9, 9, 179, 10, 13, 179, 0
  258.             printRow
  259.             call pthis
  260.             db 179, 13, 10, 0
  261.             call pthis
  262.             db 179, 9, 9, 9, 179, 10, 13, 179, 0
  263.             printRow
  264.             call pthis
  265.             db 10, 13, 192, 9, 9, 9, 217, 10, 13 ,0      
  266.            
  267. PUT_NUM     endp
  268.  
  269. pause       macro
  270.             push ax
  271.             gotoxy 0, 9
  272.             call pthis
  273.             db 'Press any key to continue . . . ', 0
  274.              
  275.            
  276.             mov ax, 0800h
  277.             int 21h
  278.             call clear_screen
  279.             pop ax
  280. endm        
  281.  
  282. printRow    macro
  283.             local row
  284.             mov cx, 3
  285.             row:
  286.                 mov al, b.[si]
  287.                 call print_num
  288.                 putc 9
  289.                 inc si
  290.             loop row
  291. endm
  292.  
  293. ret
  294.  
  295. arrayA      db 9 dup(?)
  296. arrayB      db 9 dup(?)
  297. DotArray    db 9 dup(?)
  298. CrossArray  db 9 dup(?)
  299. TransposeA  db 9 dup(?)
  300. TransposeB  db 9 dup(?)
  301. AUX         dw 9 dup(?)
  302. POSA        dw 0, 6, 12, 2, 8, 14, 4, 10, 16
  303. POSB        dw 0, 2, 4, 6, 8, 10, 12, 14, 16    
  304. l1  db 218, 9, 9, 9, 191,218, 9, 9, 9, 191, 13, 10, 0
  305. l2  db 179, 177, 9, 177, 9, 177, 9, 179, 179, 177, 9, 177, 9, 177, 9, 179, 13, 10, 0
  306. l3  db 179, 9, 9, 9, 179, 179, 9, 9, 9, 179, 13, 10, 0
  307. l4  db 179, 177, 9, 177, 9, 177, 9, 179, 179, 177, 9, 177, 9, 177, 9, 179, 13, 10, 0
  308. l5  db 179, 9, 9, 9, 179, 179, 9, 9, 9, 179, 13, 10, 0
  309. l6  db 179, 177, 9, 177, 9, 177, 9, 179, 179, 177, 9, 177, 9, 177, 9, 179, 13, 10, 0
  310. l7  db 192, 9, 9, 9, 217, 192, 9, 9, 9, 217, 13, 10, 0
  311.  
  312.     define_print_string
  313.     define_pthis
  314.     define_print_num
  315.     define_print_num_uns
  316.     define_scan_num
  317.     define_get_string
  318.     define_clear_screen
  319.        
  320.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement