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

Hi, In one of my homework problem, I have to write a MIPS program, however, I am

ID: 3623718 • Letter: H

Question

Hi,

In one of my homework problem, I have to write a MIPS program, however, I am new to MIPS and I would like learn how to write a MIPS assembly program that uses a procedure to calculate 8x-7y+z. Thanks in advance.

Here are some rules. The procedure named proc .

The "main" calling routine will ask the user for the variables (x,y,z). These values will be passed to the procedure using the appropriate registers. Before calling the procedure, set $s0 to 3010 and $s1 to 4510.

In proc, put 8x in the register $s0 and 7y in register $s1. Using these values to form the answer in $v0 before returning.

After you return to the "caller", print the registers $s0 and $s1 to show their value has not been changed by proc. Then print the result with the user's input for x,y,z

-----------------------------

Ex:

Please enter X: 8

Please enter Y: 4

Please enter Z: 6

After returning from the procedure

$s0 = 30 $s1 = 45

The result of the equation is : 42

--------------------------------------------

Explanation / Answer

please rate - thanks


    .text
    .globl main

main:   
           
    la $a0, inputx                    #Asks for x
    li $v0, 4
             syscall               
    li $v0, 5                                #Inputs x
          syscall
    move $t0,$v0                     #put x = $t0
    la $a0, inputy              #Asks for y
    li $v0, 4
             syscall
             li $v0, 5                  #inputs y
            syscall                
            move $t1,$v0                       #y=$t1
           la $a0, inputz                    #Asks for z
    li $v0, 4
           syscall
               
    li $v0, 5                                #Inputs z
          syscall

    move $t2,$v0                     #put z= $t2
             
              li $s0,30
              li $s1,45
              jal calculate
              move $t3,$v0
              la $a0,message1
    li $v0,4
    syscall
              move $a0,$s0
              li $v0 1         
    syscall
               la $a0,message2
    li $v0,4
    syscall
              move $a0,$s1
              li $v0 1         
    syscall
              la $a0,answer
    li $v0,4
    syscall
              move $a0,$t3
               li $v0 1         
    syscall
              j done
calculate:       sw $s1,save1                 #save 1st parameter
                sw $s0,save0                  #save 2nd parameter
                 li $s0,8
                 mult $s0,$t0
                 mflo $s0
                 li $s1,7
                 mult $s1,$t1
                 mflo $s1
                 li $v0,0
                 add $v0,$v0,$s0;
                 sub $v0,$v0,$s1
                 add $v0,$v0,$t2
               lw $s1,save1
              lw $s0,save0
              jr $ra

done:      la $a0,line
    li $v0,4
    syscall


#########################################################
#                                Data Segment                                                           
#########################################################
    .data

inputx:    .asciiz "Enter a value for x: "
inputy:    .asciiz "Enter a value for y: "
inputz:    .asciiz "Enter a value for z: "

message1: .asciiz "After returning from the procedure $s0 = "
message2: .asciiz "        $s1="
line:          .asciiz " --------------------------------------------------"
answer:     .asciiz " The result of the equation is :"
                          .align 4
save0:              .space 4
save1:               .space 4      

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