Question: .I can get this mips assembly code to run on mars but when I try to run it on qtpsim it does not run. Could

.I can get this mips assembly code to run on mars but when I try to run it on qtpsim it does not run. Could you tell me what my errors are in the code to get it to run?

data #this contains all of the messages to be printed out input1: .asciiz " Enter a value greater than 1: " output1: .asciiz " The number " output2: .asciiz " is perfect! " output3: .asciiz " is not perfect. " output4: .asciiz " is not perfect and prime. " outputexit: .asciiz "Exiting program." .text .globl main #this is the main program li $v0, 4 #this promts the user to input a number la $a0, input1 syscall li $v0, 5 #saves the number inputted by the user syscall move $s0, $v0 ble $v0, 1, exit_program #exits the program if the number is less than 2 move $a0, $s0 #this moves the number to $a0 jal print_sum_of_factors #jumps to the print sum function move $s1, $v0 la $a0, output1 #prints out "the number " li $v0, 4 syscall move $a0, $s0 #this prints the number li $v0, 1 syscall beq $s0, $s1, perfect_number #branches to perfect if the sum of factors is the same as the number beq $s1, 1, prime_number #branches to prime if the number is prime

li $v0, 4 la $a0, output3 #tells the user that is is not perfect syscall jal main perfect_number:

li $v0, 4 #this prints out that the number is perfect la $a0, output2 syscall jal main #jumps back to the main prime_number: li $v0, 4 #this prints out that the number is prime not perfect la $a0, output4 syscall jal main #jumps back to main

print_sum_of_factors: move $t4, $a0 #this prints out all of the factors li $t0, 1 addi $t1, $a0, 1 #adds one to $t1 addi $t2, $0, 1 #adds one to $t2 div $t1, $t1, 2 li $v0, 1 li $a0, 1 syscall print_loop: addi $t0, $t0, 1 bgt $t0, $t1, endprint_loop addi $sp, $sp, -8 sw $ra, 0($sp) sw $t0, 4($sp) move $a0, $t4 move $a1, $t0 jal is_a_factor #checks if it is a factor lw $ra, 0($sp) lw $t0, 4($sp) move $t3, $v0 addi $sp, $sp, 8 beq $t3, $0, print_loop #jumps back to the loop li $v0, 11 li $a0, 43 syscall move $a0, $t0 #moves the value to $a0 li $v0, 1 syscall add $t2, $t2, $t0 j print_loop #jumps back to the print loop endprint_loop: li $v0, 11 li $a0, 61 syscall move $a0, $t2 li $v0, 1 syscall move $v0, $t2 li $v0, 10 #syscall code for exiting syscall is_a_factor: div $a0, $a1 #this functions tests if a number is a factor or not mfhi $t0 seq $v0, $t0, $0 li $v0, 10 #syscall code for exiting syscall exit_program: li $v0, 4 #this exits the program la $a0, outputexit syscall li $v0, 10 #syscall code for exiting syscall

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!