Write a assembly 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.
TITLE matrix: C = A+B
INCLUDE Irvine32.inc
.data
AA BYTE 2, 3
BYTE 4, 5
BB BYTE 1, 3
BYTE 2, 4
CC BYTE 4 DUP(?)
msgA BYTE "MATRIX A: ",0AH,0DH,0
msgB BYTE "MATRIX B: ",0AH,0DH,0
msgC BYTE "MATRIX C=A+B ",0AH,0DH,0
.code
main PROC
; Filling Array C
MOV EAX,0H
MOV ESI,0H ; FOR INDEXING ROWS
MOV EDI,0H ;FOR INDEXING COLUMNS
MOV ECX,2H
NEXT1:
PUSH ECX ;TO SAVE CX VALUE FOR LOOP1
MOV ECX,2H
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
;-------------------------------------------------
mov edx, OFFSET msgA ; address of string msgA
call writeString ; writes a string "A:"
; Display Array A
MOV EAX,0H
MOV ESI,0H ; FOR INDEXING ROWS
MOV EDI,0H ; FOR INDEXING COLUMNS
MOV ECX,2H
NEXTA1:
PUSH ECX ; TO SAVE CX VALUE FOR LOOP1
MOV ECX,2H
NEXTA2:
MOV EBP,EDI
MOV AL, AA[EBP][ESI]
CALL WriteDec ; display CC[i,j]
mov al, ' '
call WriteChar
INC EDI
LOOP NEXTA2
CALL Crlf
DEC EDI
INC ESI ;TO MOVE TO NEXT ROW
POP ECX ;USES THE VALUE OF CX FOR LOOP1
LOOP NEXTA1
call Crlf
;-------------------------------------------------
mov edx, OFFSET msgB ; address of string msgB
call writeString ; writes a string "B:"
;-------------------------------------------------
; Display Array B
MOV EAX,0H
MOV ESI,0H ; FOR INDEXING ROWS
MOV EDI,0H ; FOR INDEXING COLUMNS
MOV ECX,2H
NEXTB1:
PUSH ECX ; TO SAVE CX VALUE FOR LOOP1
MOV ECX,2H
NEXTB2:
MOV EBP,EDI
MOV AL, BB[EBP][ESI]
CALL WriteDec ; display CC[i,j]
mov al, ' '
call WriteChar
INC EDI
LOOP NEXTB2
CALL Crlf
DEC EDI
INC ESI ;TO MOVE TO NEXT ROW
POP ECX ;USES THE VALUE OF CX FOR LOOP1
LOOP NEXTB1
call Crlf
;-------------------------------------------------
mov edx, OFFSET msgC ; address of string msgC
call writeString ; writes a string "C:"
;-------------------------------------------------
; Disdlay Array C
MOV EAX,0H
MOV ESI,0H ; FOR INDEXING ROWS
MOV EDI,0H ; FOR INDEXING COLUMNS
MOV ECX,2H
NEXTC1:
PUSH ECX ; TO SAVE CX VALUE FOR LOOP1
MOV ECX,2H
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
Comments
Leave a comment