# Math Calculations in MIPS Assembly Assignment Sample

Write a program to solve the equation (3x+7)(2x+8), try with initial values of 0, 1 for x as that will make it easier to debug. Evaluate the expression 17xy – 12x – 6y + 12. Use symbolic addresses for x, y and answer. Write a program to calculate the average value of a byte array. Sum all the values from 1 to 100 using a loop. For more assembly language assignment help contact us for details.

Solution:

q1.asm

.text
main:
addi \$t0, \$0, 10 #storing the x
mult \$t1, \$t0 #3x
mflo \$t3
mult \$t0, \$t2 #2x
mflo \$t5
div \$t7, \$t4, \$t6 #(3x+7)/(2x+8)
add \$10, \$t7, \$0 #storing in \$10 register

q2.asm

.data
x: .word 1
y: .word 1

.text
main:
lw \$t0, x
lw \$t1, y
mult \$t0, \$t1 #xy
mflo \$t5
mult \$t5, \$t2 #17xy
mflo \$t5
mult \$t0, \$t3 #12x
mflo \$t6
mult \$t1, \$t4 #6y
mflo \$t7
sub \$t8, \$t5, \$t6 #17xy-12x
sub \$t8, \$t8, \$t7 #17xy-12x-6y
add \$10, \$t8, \$t4 #17xy-12x-6y+12, storing in \$10

q3.asm

.data
x1: .byte 12
x2: .byte 97
x3: .byte 133
x4: .byte 82
x5: .byte 236

.text
main:
lbu \$s0, x1 # load byte from memory & store as unsined int
lbu \$s0, x2
lbu \$s0, x3
lbu \$s0, x4
lbu \$s0, x5

divu \$s1, \$t0 # sum/5
mflo \$s1

sw \$s1, 0(\$sp) # store in a memory location
addi \$10, \$s1, # put result in \$10

li \$v0, 10
syscall

q4.asm

.data
.text
main:
addi \$15, \$0, 0 # sum
addi \$s1, \$0, 1 # counter
addi \$s2, \$0, 101 # termination

loop:
beq \$s1, \$s2, exit
add \$15, \$15, \$s1 # sum += counter
addi \$s1, \$s1, 1 # counter ++
j loop

exit:
j exit
sll \$0, \$0, 0