Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using arithmetic, basic I/O, and branches, write a program in MIPS32 assembly la

ID: 672248 • Letter: U

Question

Using arithmetic, basic I/O, and branches, write a program in MIPS32 assembly language instruction that will solve and output the result of any one of 4 fixed expressions. You are required to get the inputs to the expression from the user, and display the result. The choice of which expression to solve must be presented to the user in the form of a menu. All inputs are integers, and should be handled as words. The expressions are: 2 * ((3A + B) * 2C) 4(A + C -1) -(B/2) (A + (B + 3))*(C - 2) (A/(B * B +1)) % C Despite Mars 4.4 having the instruction subi, it is not a true MIPS32 assembly language instruction, thus you are not permitted to use it. (i.e. You cannot subtract an immediate value from a register, even though the simulator will allow it). mul and div are REGISTER instructions. That means all their operands must be registers. In the case of the Mars simulator, immediate values are allowed, but will not be accepted for this assignment. Your program must terminate itself. (No hanging code) Example Output: Y = 2 * ((3A + B) * 2C) Y = 4(A + C -1) - (B/2) Y = (A + (B + 3))*(C - 2) Y = (A/(B * B + 1))%C Please enter your choice: 4 Enter a value for A: 18 Enter a value for B: -1 Enter a value for C: 2 The result is: Y = 1 *The values in red are user inputs*

Explanation / Answer

lw $t0 ,($gp)      # fatch i

bltz $t0, def # y<0 -> Default

slti $t1 , $zero ,4 # y<4

beg $t1 ,$zero, def # default value

sll $t0 , $t0 ,3         

add $t2 , $t1, $gp    

sll $t2 , $t2 ,2        

add $t3 , $t2, $gp

sll $t3 , $t3 ,1      

add $t4 , $t3, $gp

lw $t5,1064($t2)            #fatch branch Table

jr $t5

is1 : sw $t0 , 1

       lw $t6 , 4($gp)     #fatch 2

      add $t11,$$t6,$zero # copy of 2

      lw $t7 , 4($gp) #fatch 3

      lw $t8 , 4($gp)   #fatch A

     mul $t7,$t7,$t8    # 3* A

     lw $t9 , 4($gp)   #fatch B

    add $t9, $t9, $t7   # 3A+B

mul $t6,$t6,$t9        #2*(3A+B)

    lw $t10 , 4($gp)     #fatch C

    mul $t10,$t10,$t11       #2C

    mul $t11,$t11,$t6        #2*(3A+B)*2C

     sw $t6, 0($gp)           # y= ...

j : done

is2 : addi $t1, $t2 , 1        # case 2

        lw $t12 , 4($gp)      #fatch 4

       add $t8, $t8, $10    # A + C

       lw $t13 , 4($gp)      #fatch 1

      sub $t13 , $t13, $t8    # A + C - 1

      lw $t14 , 4($gp)      #fatch B

    div $t14 ,$t14, $t13   #B/2

    sub $t14 , $t14, $t13    #(A+C-1)-(B/2)

      MUL $t12, $t12, $t14    # 4 * (A+C-1)-(B/2)

       sw $t6, 0($gp)           # y= ...

j : done

      

      

      

    

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote