Wednesday, 21 October 2009

More Mips

So this week I have been getting stuck into Mips alot. For the past week i have been working through some exercises that get you used to the bassic functions, such as 'addu' (add) subu(subtrat) and multu(multiply). We have also been learning about all the registers that you can (and can't) play about with, and have also been looking at lw (load word) and sw(store word) to take values from memory into a register, and also store from a register into memory.

Below is an example exercise that i achieved, i checked to see if this was correct, substituting x and y with different values, and it seem to work well =D.

This week i have been learning about loops, and the Mips substitute for the "while" loop, and if statements based on greater/less than and boolean conditions. Im currrentley going through these exercies now, and will post one once i have done them and tested them appropriatley =D.




## Evaluate the expression 17xy - 12x - 6y + 12

.text
.globl main

main:

#x = $10
lui $11,0x1001 ##gives register 11 memory address 0x1001
lw $10,($11) ##loading value from memory address 0x1001
#y = $12
lw $12,4($11) ##loading value from memory address 0x1001(offset 4)

ori $13,$0,17 ##giving $13 the value 17
multu $10,$12 ##multiplying x and y
mflo $14 ##putting x and y multiplied into $14
multu $14,$13 ##multiplying x and y multiplied by 17
mflo $14 ##17xy

ori $13,$0,12 ##giving $13 the value 12
multu $13,$10 ##multiplying 12 and x(10)
mflo $15 ##12x

ori $13,$0,6 ##giving $13 the value 6
multu $13,$12 ##multiplying 6 and y(1)
mflo $13 ##6y

ori $12,$0,12 ##giving $12 the value 12
subu $10,$14,$15 ##17xy - 12x
subu $10,$10,$13 ##17xy - 12x - 6y
addu $10,$10,$12 ##17xy - 12x - 6y + 12

sw $10,poly ##giving poly the value of equation



.data

x: .word 10
y: .word 1
poly: .word 0


0 comments:

Post a Comment