Answer to Question #241328 in Assembler for xyz

Question #241328

Write a program that takes two 2-D matrixes A and B. Add value of the matrixes and store it in different matrix called C. NB: Implement the above problem inside Main Procedure.


1
Expert's answer
2021-09-26T11:41:46-0400
TITLE  matrix:  C = A+B
INCLUDE Irvine32.inc

.data
AA  BYTE  9 DUP(?)
BB  BYTE  9 DUP(?)
CC  BYTE  9 DUP(?)

msgA    BYTE "A[",0
msgB    BYTE "B[",0
msgQ    BYTE "] = ",0

.code
main PROC
; Filling Array A
     XOR EAX, EAX
     XOR EBX, EBX
     XOR ESI, ESI          ; FOR INDEXING ROWS
     XOR EDI, EDI          ;FOR INDEXING COLUMNS
     MOV ECX,3H

NEXT1A:
   PUSH ECX             ;TO SAVE CX VALUE FOR LOOP1
   MOV ECX,3H

NEXT2A:    
   MOV EBP,EDI

   mov edx, OFFSET msgA        ; address of string msgA
   call writeString            ; writes a string "A["

   mov EAX, ESI
   call WriteDec

   mov  al, ','
   call WriteChar

   mov EAX, EDI
   SUB EAX, EBX
   call WriteDec
      
   mov edx, OFFSET msgQ        ; address of string msgQ
   call writeString            ; writes a string "] = "      
      
   CALL ReadDec                    ; AA[i,j]
   MOV AA[EBP][ESI], AL
   INC EDI
   LOOP NEXT2A
     
   DEC EDI
   INC EBX
   INC EBX
   INC ESI             ;TO MOVE TO NEXT ROW

   POP ECX             ;USES THE VALUE OF CX FOR LOOP1
   LOOP NEXT1A   

;------------------------------------------------------------
       call Crlf
; Filling Array B
     XOR EAX, EAX
     XOR EBX, EBX
     XOR ESI, ESI          ; FOR INDEXING ROWS
     XOR EDI, EDI          ;FOR INDEXING COLUMNS
     MOV ECX,3H
 
NEXT1B:
   PUSH ECX             ;TO SAVE CX VALUE FOR LOOP1
   MOV ECX,3H
NEXT2B:    
   MOV EBP,EDI

   mov edx, OFFSET msgB        ; address of string msgA
   call writeString            ; writes a string "B["

   mov EAX,  ESI
   call WriteDec

   mov  al, ','
   call WriteChar

   mov EAX, EDI
   SUB EAX, EBX
   call WriteDec
      
   mov edx, OFFSET msgQ        ; address of string msgA
   call writeString                ; writes a string "] = "      
      
   CALL ReadDec                    ; AA[i,j]

   MOV BB[EBP][ESI],AL
   INC EDI
   LOOP NEXT2B
     
   DEC EDI
   INC ESI             ;TO MOVE TO NEXT ROW

   POP ECX             ;USES THE VALUE OF CX FOR LOOP1
   LOOP NEXT1B   

; Filling Array C
     MOV EAX,0H
     MOV ESI,0H          ; FOR INDEXING ROWS
     MOV EDI,0H          ;FOR INDEXING COLUMNS
     MOV ECX,3H

NEXT1:
   PUSH ECX             ;TO SAVE CX VALUE FOR LOOP1
   MOV ECX,3H
NEXT2:    
   MOV EBP,EDI
   MOV AL, AA[EBP][ESI]
   ADD AL,BB[EBP][ESI]
   MOV CC[EBP][ESI],AL
   INC EDI
   LOOP NEXT2
     
   DEC EDI
   INC EBX
   INC EBX
   INC ESI             ;TO MOVE TO NEXT ROW

   POP ECX             ;USES THE VALUE OF CX FOR LOOP1
   LOOP NEXT1   

    call Crlf
;-------------------------------------------------
; Disdlay Array C
   MOV EAX,0H
   MOV ESI,0H          ; FOR INDEXING ROWS
   MOV EDI,0H          ; FOR INDEXING COLUMNS
   MOV ECX,3H

NEXTC1:
    PUSH ECX             ; TO SAVE CX VALUE FOR LOOP1
   MOV ECX,3H
NEXTC2:    
    MOV EBP,EDI
    MOV AL, CC[EBP][ESI]
   CALL WriteDec            ; display CC[i,j]
   mov  al, ' '
   call WriteChar    

   INC EDI
   LOOP NEXTC2
   CALL Crlf  
   DEC EDI
   INC ESI             ;TO MOVE TO NEXT ROW

   POP ECX             ;USES THE VALUE OF CX FOR LOOP1
    LOOP NEXTC1  

    exit
main ENDP

end main




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS