Question: This was my initial instru 1) Write a program that asks user How many positive numbers that are divisible by 6 do you want to

This was my initial instru

1) Write a program that asks user How many positive numbers that are divisible by 6 do you want to add?. Your loop counter would be the user input. If the user enters a positive number between 1 and 100 that is divisible by 6, you increment your loop counter and add it to the sum. You need to decide if the positive number entered by the user is divisible by 6 or not. Your program should print an error message if the number is not within the range and ask user for another number An Example of sample input and output would be:

==============================================

How many positive number that is devisable by you want to add? 3

Enter a number: 36 ==>

36 is divisible by 6

Enter a number: -20 ==>

**** ERROR: -20 is not a positive number. Enter another number.

Enter a number: 0 ==>

**** ERROR: 0 is not in the range of 1 to 100. Enter another number.

Enter a number: 21 ==>

21 is not divisible by 6. Enter another number.

Enter a number: 121 ==>

**** ERROR: 121 is not in the range of 1 to 100. Enter another number.

Enter a number: 6 ==> 6 is divisible by 6

Enter a number: 12 ==> 12 is divisible by 6

The Sum of the positive numbers between 1 and 100 that are devisable by 6, is: 54

=============================================

This is supposed to be done using the MARS simulator for the MIPS Processor.

using code such as beq, syscall, add $s0, $v0, $0 and other code that looks similar to this.

It is important that the user is prompted with "# is divisible by 6" after entering a correct value.

Please keep the answer as simple as possible. Comments are incredibly appreciated.

Please try to use "add" instead of "move" to place input values into a register, and if a remainder is required, use mfhi/mflo to solve.

If there are any questions or requests to change my question please comment and I will try to update it.

Thank you, and I will upvote whoever can correctly follow all the instructions.

There is only one thing missing in my code. I'm trying to add the verification of "(inputted number) is divisible by 6". That's all i need to add. so if you could make the changes to my code so that that will be included, I would appreciate it greatly.

This is the code I currently have:

.data str: .asciiz "How many positive numbers that are divisible by 6 do you want to add? " str1: .asciiz " Enter a number: " str2: .asciiz " The Sum of the positive numbers between 1 and 100 that are devisable by 6, is: " str3: .asciiz " is not divisible by 6. Enter another number. " str4: .asciiz " is not a positive number. Enter another number." str5: .asciiz "**** ERROR: " str6: .asciiz " is not in the range of 1 to 100. Enter another number. "

.text #print prompt for user input li $v0,4 la $a0,str syscall #user input for amt of numbers to add li $v0,5 syscall move $t1,$v0 #save to t1

li $s0,0 #number that is divisible by 6 li $s3,0 #total of numbers that are divisble by 6

loop: #prompts str1 li $v0,4 la $a0,str1 syscall

#user input for entering a number li $v0,5 syscall move $s1,$v0

bltz $s1,negativeNumber beqz $s1,notInRange bgt $s1,100,notInRange

div $s2,$s1,6 #divide by 6 mfhi $s2 #move remaining to s2 bnez $s2,skipNumber add $s0,$s0,1 #increase count by one add $s3,$s3,$s1 #add to final total j next skipNumber: li $v0,1 move $a0,$s1 syscall li $v0,4 la $a0,str3 #it will print prompt syscall next: #check if value of initial input for numbers is equal. if so, exit. if not, loop li $v0, 1 li $v0 syscall beq $s0,$t1,exit #jump to 'loop:' if not enough values entered j loop

negativeNumber: #error prompt li $v0,4 la $a0,str5 syscall

li $v0,1 move $a0,$s1 syscall

#negative number prompt li $v0,4 la $a0,str4 syscall #jump to 'loop:' if negative j loop

notInRange: #error prompt li $v0,4 la $a0,str5 syscall li $v0,1 move $a0,$s1 syscall #not in range prompt li $v0,4 la $a0,str6 syscall #jump to 'loop:' if not in range j loop

exit: #print sum prompt li $v0,4 la $a0,str2 syscall #print sum li $v0,1 move $a0,$s3 syscall

li $v0, 10 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!