Question: This program runs are MARS. the program is slightly written out but now it has to run between -100 and 100; please see the #'s
This program runs are MARS. the program is slightly written out but now it has to run between -100 and 100; please see the #'s for more details. thanks
#int main() { # int x; # printf("Please enter a number between -100 and 100; # scanf("%d",&x); // Reads input into x # if (x < -100 || x > 100) # printf("Can't you read"); # else if (x < 0) # printf("Such a negative response"); # else if (x > 0) # printf("Such a positive response"); # else # printf("Fence Sitter!!!"); # printf("Thanks for playing!"); # return 0; # }
.text .globl main main: # Prompt and get an int from the user la $a0, PROMPT li $v0, 4 syscall li $v0, 5 syscall move $t0, $v0 # X is now in $t0 for use on conditionals # Begin our if statement # BeginIf slt $t1, $t0, $zero # Checking if x < 0 beqz $t1, ELSEIF # If false, go to ELSEIF # logic la $a0, NEGATIVE li $v0, 4 syscall b ENDIF ELSEIF: sgt $t1, $t0, $zero # Check if x > 0 beqz $t1, ELSE # logic la $a0, POSITIVE li $v0, 4 syscall b ENDIF ELSE: # logic la $a0, FENCESITTER li $v0, 4 syscall
ENDIF: li $v0, 10 syscall .data PROMPT: .asciiz "Enter a number" NEGATIVE: .asciiz "Such a negative response" POSITIVE: .asciiz "Such a positive response" FENCESITTER: .asciiz "Fence Sitter!!!"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
