Question: .data .align 0 # Define strings used in each of the printf statements msg1: .asciiz Welcome to Prime Tester msg2: .asciiz Enter a number
.data
.align 0
# Define strings used in each of the printf statements msg1: .asciiz "Welcome to Prime Tester " msg2: .asciiz "Enter a number between 0 and 100: " msg3: .asciiz "Error: Invalid input for Prime Tester " msg4: .asciiz "The entered number is prime " msg5: .asciiz "The entered number is not prime " ec_msg: .asciiz " is prime " # Reserved for use in extra credit
.align 2 .text .globl main
main: # This series of instructions # 1. Displays the welcome message # 2. Displays the input prompt # 3. Reads input from the user display_string msg1 # Display welcome message display_string msg2 # Display input prompt li $v0, 5 # Prepare the system for keyboard input syscall # System reads user input from keyboard move $a1, $v0 # Store the user input in register $a0 j code # Go to the code label
error: display_string msg3 # Display error message j exit isprime: display_string msg4 # Display is prime message j exit notprime: display_string msg5 # Display not prime message exit: li $v0, 10 # Prepare to terminate the program syscall # Terminate the program
# Place all your code below the code label code:
# c code # if(input < 0 || input > 100) # { # printf("Error: Invalid input for Prime Tester "); # exit(0); #}
slti $t0, $a1, 0 #right now $t0 is 1 if $a1 is less than zero or 0 if greater sge $t1, $a1, 100 #if $a1 is greater than 100 than $t1 = 1 else = 0 or $t2, $t0, $t1 # now the decision of the if staement is stored in $t2 # if this value is = 1 then move to error message then exit else exit beq $t2, 1, error
....................................................................................................................................
Below is my output:
Welcome to Prime Tester
Enter a number between 0 and 100: 5
-- program is finished running (dropped off bottom) --
....................................................................................................................................
Why am I receiving this output and not the error label? how can I print the error label using the code in italics that I have written?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
