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

code must be done in mips 32 add comments and make sure to follow step 7 and use

ID: 3716845 • Letter: C

Question

code must be done in mips 32 add comments and make sure to follow step 7 and use jr ra and not the exit syscalll thank you

1 Project.par Project2.pdf 1 13 (1) Print the following prompt message Plcase enter a non-zero natural number less than 32,768 (2) Read an integer from the user (3) Repeat the above process (Step 1 and 2) five times. (4) Check whether or not all the five integers are larger than 0 and less than 32768. Ifnot, repeat Steps 1 through 4 (5) Call a prucedure (subprogram) that calculates the result of A+B/(C D x E), where A, B. C, D and E are the five integers entered. The procedure should returm the result. Use the appropriate MIPS calling conventions, and the usual order of operations. Note: you need to pass 5 values to the subprogram, but can only pass four of them using the argument registers. The fifth value must be passed using the stack! (6) Print the following message: Where A, B, C, D and E should he replaced by the integers entered, and X is the value of the expression calculated at Step 5. (T) Return from main using jr Sra (not using the exit syscal1). The jr should not cause an error, and if it does then your program is not using the stack properly. 3:12 PM O Type here to search 425/2018 21

Explanation / Answer

.DATA

list       .word 5 DUP(?)

X                     .word  

inp                   .asciz               "Please enter a natural number less than 32,768: $"

.MAIN

la                     $t3, list

li                      $t1, 0

LOOP:

cmp                 $t1, 5

beq                  NEXT

# index * 4 for offset, add offset to base address

add                  $t1, $t1, $t1

add                  $t1, $t1, $t1

add                  $t2, $t1, $t3

# print inp string

li      $v0, 4

la      $a0, inp

li      $a1, 64

syscall

# read number and save to memory

syscall 5

cmp                 $v0, 32768

bge                  LOOP

cmp                 $v0, 0

blt                    LOOP

sw                    $v0, 0($t2)                             

inc                   $t1

NEXT:

push     0(list)                           # A

push     4(list)                           # B

push     8(list)                           # C

push     12(list)                         # D

push     16(list)                         # E

jal                    calc

_exit

calc:

pop                  ebp

mov                 ebp, esp

mov                 $t0, 16(ebp)                 # A

mov                 $t1, 12(ebp)                 # B

add                  $t0, $t0, $t1                # A+B

mov                 $t1, 4(ebp)                   # D

mov                 $t2, 0(ebp)                   # E

mul                  $t1, $t2, $t1                # DxE

mov                 $t2, 8(ebp)                   # C

sub                   $t2, $t2, $t1                # C - D x E

div                   $t0, $t0, $t2

sw                    $t0, X

pop                  ebp

jr                      $ra