Write a MIPS program to add two matrices and store the result in memory starting
ID: 3819883 • Letter: W
Question
Write a MIPS program to add two matrices and store the result in memory starting at address given in s4. The matrices are of the size 2 X 3 each. Deliverables: The two matrices are stored starting at two memory locations whose addresses are given in two registers, s2 and s3. Each number in the matrix is represented in signed 2's complement form. The Code with detailed comments Flowchart of the Short description of the approach and the program flow Simulation input(s) and results For two matrices that are stored at starting addresses given by s0 and s1 respectively, with Mi of size 2 X 3 and M2 is of size 3 X 2, perform the multiplication of M1 X M2 and store the result in memory starting at address given in s2. Each number in the matrix is represented in signed 2's complement form. Deliverables: The Code with detailed comments Flowchart of the Short description of the approach and the program flow Simulation input(s) and resultsExplanation / Answer
; Declaration
.SECTION DATA
M DB 01H,02H,03H ; Matrix M is a 2x3 Matrix
N DB 04H,05H,06H ; Matrix N is a 2x3 Matrix
CNT DB 04H
.CODE
START: MOV AX,@DATA
MOV DS,AX
MOV CL,CNT ; CL is loaded with CNT for looping
LEA S2 ,M ; S2 is loaded with address of Matrix M
LEA S3,N ; S3 is loaded with address of Matrix N
;Matrix Addition
L1:
MOV AL,S2
MOV BL, S3
ADD AL,BL ; Add the Matrices
PUSH AX ; Push the result for storing Operations
LOOP L1
CALL STORE
;Store Part
STORE PROC
POP AX ; POP the Unwanted values first
LEA S4,RES
ADD S2,04H
MOV CL,04H
L2:POP AX ; POP the last stored result.
MOV S4,AL ; store the result in S4.
LOOP L2
INT 3H ; Since Storing is completed terminate the program
RET
STORE ENDP
END START
Result:
4 8 12 16 20 24
; Declaration
.SECTION DATA
M DB 01H,02H,03H ; Matrix M is a 2x3 Matrix
N DB 04H,05H,06H ; Matrix N is a 2x3 Matrix
CNT DB 04H
.CODE
START: MOV AX,@DATA
MOV DS,AX
MOV CL,CNT ; CL is loaded with CNT for looping
LEA S2 ,M ; S2 is loaded with address of Matrix M
LEA S3,N ; S3 is loaded with address of Matrix N
;Matrix Addition
L1:
MOV AL,S2
MOV BL, S3
ADD AL,BL ; Add the Matrices
PUSH AX ; Push the result for storing Operations
LOOP L1
CALL STORE
;Store Part
STORE PROC
POP AX ; POP the Unwanted values first
LEA S4,RES
ADD S2,04H
MOV CL,04H
L2:POP AX ; POP the last stored result.
MOV S4,AL ; store the result in S4.
LOOP L2
INT 3H ; Since Storing is completed terminate the program
RET
STORE ENDP
END START
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.