Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS A MIPS ASSEMBLY PROGRAM AND IS TO BE WRITTEN AS SUCH. THERE IS PROVIDED CODE BELOW THAT SHOULD NOT BE ALTERED. This program

THIS IS A MIPS ASSEMBLY PROGRAM AND IS TO BE WRITTEN AS SUCH.

THERE IS PROVIDED CODE BELOW THAT SHOULD NOT BE ALTERED.

This program is the first part of a three-part program. The program comes in three parts because the final program is complex, and youll be much more successful if you get each successive stage correct before proceeding on to the next.

Overall, the program solves 3 linear equations in three variables by using 3x3 determinants.

This particular problem is

17A + 12B + 17C = 562

14A + 5B + 17C = 441

2A + 2B + 14C = 180

The coefficients are written as three rows of four data items at the beginning of the boilerplate code. The layout of the data in memory, as before, is a single linear vector. Its up to you to organize it properly to be able to perform the computations.

In order to solve the problem, we need to use the data to create four 3x3 matrices.

We start by noting a 3 x 4 matrix from the information above:

Column

Row

A

B

C

D

1

17

12

17

562

2

14

5

17

441

3

2

2

14

180

Somewhat counterintuitively, but this will make sense in a minute, the D matrix is columns A B and C of the above matrix, i.e.,

17

12

17

14

5

17

2

2

14

The other matrices are created by substituting column D for the column whose name is the name of the matrix:

A

B

C

562

12

17

441

5

17

180

2

14

17

562

17

14

441

17

2

180

14

17

12

562

14

5

441

2

2

180

Creating each of these 3x3 matrices from the original 3 x 4 matrix is the goal of this assignment. The method you will write is MakeDet, found at the bottom of this boilerplate code:

***THIS SHOULD NOT BE ALTERED AND WHAT SHOULD BE WRITTEN IS BELOW THE MakeDet: LINE

.data

# 17A + 12B + 17C = 562

# 14A + 5B + 17C = 441

# 2A + 2B + 14C = 180

Data:

.word 17, 12, 17, 562

.word 14, 5, 17, 441

.word 2, 2, 14, 180

Scratch:

.space 48

ABC:

.space 9

TextA:

.asciiz "Matrix A: "

TextB:

.asciiz "Matrix B: "

TextC:

.asciiz "Matrix C: "

TextD:

.asciiz "Matrix D: "

crlf:

.asciiz " "

Tab:

.asciiz "\t"

.text

la $a0, Data

la $a1, Scratch

addi $a2, $0, 0

jal MakeDet

addi $a0, $a1, 0

la $a1, TextD

jal PrintDet

la $a0, Data

la $a1, Scratch

addi $a2, $0, 1

jal MakeDet

addi $a0, $a1, 0

la $a1, TextA

jal PrintDet

la $a0, Data

la $a1, Scratch

addi $a2, $0, 2

jal MakeDet

addi $a0, $a1, 0

la $a1, TextB

jal PrintDet

la $a0, Data

la $a1, Scratch

addi $a2, $0, 3

jal MakeDet

addi $a0, $a1, 0

la $a1, TextC

jal PrintDet

addi $v0, $0, 10

syscall

PrintDet:

# $a0 - address of array

# $a1 - address of label to print

# $t0 - i

# $t1 - j

# $t2 - loop Limit (same for i and j)

# $t3 - $a0 to manipulate

addi $sp, $sp, -8

sw $a0, 0($sp)

sw $a1, 4($sp)

addi $t0, $0, 0

addi $t1, $0, 0

addi $t2, $0, 3

addi $t3, $a0, 0

addi $a0, $a1, 0

addi $v0, $0, 4

syscall

PrintLoop:

lw $a0, 0($t3)

addi $v0, $0, 1

syscall

la $a0, Tab

addi $v0, $0, 4

syscall

addi $t0, $t0, 1

addi $t3, $t3, 4

bne $t0, $t2, PrintLoop

addi $t0, $0, 0

addi $t1, $t1, 1

la $a0, crlf

addi $v0, $0, 4

syscall

bne $t1, $t2, PrintLoop

syscall

lw $a1, 4($sp)

lw $a0, 0($sp)

addi $sp, $sp, 8

jr $ra

MakeDet:

# $a0 - original 3 x 4 data array

# $a1 - address of resulting array

# $a2 - Column (0-3)

# $s0 - i counter

# $s1 - j counter

There is no return value (in a $v register) because the base address of the array passed in argument $a1 is where the answer goes.

Since you know your input data matrix is 3x4 and that your output matrix is 3x3, you can get away with writing each matrix (0=D, 1=A, 2=B, 3=C) explicitly instead of creating loops within loops within loops.

If you have done your work correctly, the output should look like:

Matrix D:

17 12 17

14 5 17

2 2 14

Matrix A:

562 12 17

441 5 17

180 2 14

Matrix B:

17 562 17

14 441 17

2 180 14

Matrix C:

17 12 562

14 5 441

2 2 180

-- program is finished running --

Remember that when your program is graded, it will be run with a 3x4 matrix that is different from the one above so you may not code any explicit values.

Good Luck!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

Describe alternative paid time off policies.

Answered: 1 week ago

Question

Describe customized benefit plans.

Answered: 1 week ago