Computer Engineering Project Collection

-->

Saturday, January 31, 2009

MIPS - Determinant of 2x2 matrix

This is the first of 3 Problems I got regarding the MIPS. The problems are given to make the students get used to MIPS assembly language. The simulation is performed using MIPS32 Simulator called PC SPIM, which can be acquired freely at http://pages.cs.wisc.edu/~larus/spim.html

The first problem is :

Create a program to compute determinant of a 2x2 matrix. Remember how a a 2-D array is
stored in memory. Result is stored in memory. Use integer only operations and assume all
result are 32-bit.

The idea is to put the matrix into the memory in the following order : [a00,a01,a10,a11], then do a calculation of determinant. If the result is negative than it must be inverted (because the absolute mark).
Here is the resulting code:

.data 0x10010000
.word 2,1,3,4
.space 4
.text
.globl main

main: addu $s0,$ra,$0
lui $s1,0x1001
lw $t0, 0($s1)
lw $t1, 4($s1)
lw $t2, 8($s1)
lw $t3, 12($s1)
mult $t0,$t3
mflo $s2
mult $t1,$t2
mflo $s3
sub $s4,$s2,$s3
slt $t4,$s4,$0
beq $t4,$0,oke
nor $s4,$s4,$0
addi $s4,$s4,1
oke: sw $s4,16($s1)
addu $ra,$0,$s0
jr $ra

Labels: , , ,

1 Comments:


  • Thanks for Sharing this informative blog, it helps alot well, Before you sell or trade your broken car Brisbane, you should first get a reliable estimate of its value.
    when it comes to giving you the top cash for cars.
    Knowing the monetary value of your car is an important first step toward hassle free car removal Brisbane

    By Blogger Salis Fandom, At 8:45 PM  

Post a Comment

Subscribe to Post Comments [Atom]



<< Home