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