Question

Assembler lanaguage program   The program is to prompt the user to enter a number between 2...

Assembler lanaguage program  

The program is to prompt the user to enter a number between 2 and 100. Reject any invalid user inputs and terminate the program if invalid inputs are entered. Print each even number from 2 to the user entered number. Sum these even numbers and print the sum. Print each odd number from 1 to the user entered number. Sum these odd numbers and print the sum. Exit the program when the output is complete.


The output of your program should look something like this:
Enter an integer between 1 and 100.
You entered 10.
The even numbers from 1 to 10 are:
2
4
6
8
10
The even sum is: 30
The odd numbers from 1 to 10 are:
1
3
5
7
9
The odd sum is: 25

Homework Answers

Answer #1

Here is the code:
.text
main:
la $a0, user #ask the user for input
li $v0, 4
syscall
li $v0, 5 #syscall for reading user input
syscall
move $s0, $v0 #$s0 will have the user input now
la $a0, output #print the input from user
li $v0, 4
syscall
move $a0, $s0
li $v0, 1
syscall
la $a0, endl
li $v0, 4
syscall
blt $s0, 2, quit #check if within limits
bgt $s0, 100, quit
li $s1, 2 #this will iterate from 2 to input
li $s2, 0
la $a0, evenNum
li $v0, 4
syscall
move $a0, $s0
li $v0, 1
syscall
la $a0, endl
li $v0, 4
syscall
eveniter:
move $a0, $s1 #print current number
li $v0, 1
syscall
la $a0, endl
li $v0, 4
syscall
add $s2, $s2, $s1 #add into the sum
addi $s1, $s1, 2
bgt $s1, $s0, doneeven #if user input is reached then done
j eveniter #continue iterating otherwise
doneeven:
la $a0, evenSum #print the sum
li $v0, 4
syscall
move $a0, $s2
li $v0, 1
syscall
la $a0, endl
li $v0, 4
syscall
li $s1, 1 #now odd numbers
li $s2, 0
la $a0, oddNum
li $v0, 4
syscall
move $a0, $s0
li $v0, 1
syscall
la $a0, endl
li $v0, 4
syscall
odditer:
move $a0, $s1 #print the current number
li $v0, 1
syscall
la $a0, endl
li $v0, 4
syscall
add $s2, $s2, $s1 #add into the sum
addi $s1, $s1, 2
bgt $s1, $s0, doneodd #if user input is reached then done
j odditer #otherwise continue iterating
doneodd:
la $a0, oddSum #print the sum
li $v0, 4
syscall
move $a0, $s2
li $v0, 1
syscall
la $a0, endl
li $v0, 4
syscall
li $v0, 10 #exit the program
syscall
quit:
la $a0, errorMessage #print error message
li $v0, 4
syscall
li $v0, 10
syscall
.data
user: .asciiz "Enter an integer between 1 and 100: "
output: .asciiz "You entered "
endl: .asciiz "\n"
evenNum: .asciiz "The evenNum numbers from 1 to "
oddNum: .asciiz "The oddNum numbers from 1 to "
are: .asciiz "are:\n"
evenSum: .asciiz "The evenNum sum is: "
oddSum: .asciiz "The oddNum sum is: "
errorMessage: .asciiz "Input out of bounds\n"

Here are some outputs in the screenshots:

Comment in case of any doubts.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C++ program to prompt a user for a positive integer and print the number...
Write a C++ program to prompt a user for a positive integer and print the number of even and odd digits (0 is even). Sample run: Enter a positive integer: -4580 Invalid. Enter a positive integer: 12146 2 odd digits 3 even digits
Write a program that takes n integer numbers from the user, and then counts the number...
Write a program that takes n integer numbers from the user, and then counts the number of even numbers and odd numbers and print them to the screen. Sample Output: Enter how many numbers you have: 10 Enter the 10 numbers: 1 3 19 50 4 10 75 20 68 100 The number of even numbers is: 6 The number of odd numbers is: 4 (( in java ))
Write a complete C++ program asking the user to enter numbers one by one. User enters...
Write a complete C++ program asking the user to enter numbers one by one. User enters only whole numbers 0 and 10. Once the user enters 0, then the program should print sum of only odd numbers entered by user prior to 0. A valid scenario given below: Enter a number: 5 Enter a number: 3 Enter a number: 2 Enter a number: 3 Enter a number: 8 Enter a number: 0 Sum of the odd numbers you entered is...
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
design a program that prompts the user to enter a positive integer number and reads the...
design a program that prompts the user to enter a positive integer number and reads the user’s input. If the user input is not a positive number, the program should prompt them repeatedly until they enter a valid input. Once a valid input is received ,the program uses a loop to calculate the sum of the digits of the user’s input and displays the sum. For example, if the user enters the number 94311, the program should print the sum...
Ask the user for integers. If the user did not enter an integer, ask again. (Type...
Ask the user for integers. If the user did not enter an integer, ask again. (Type Safe Input) Keep a running total of the intergers entered (sum). Once the user enters 0, stop looping. Print the sum of all the numbers. Enter an integer, 0 to stop> [fasdfsa] Invalid input. Enter an integer, 0 to stop> [231.342] Invalid input. Enter an integer, 0 to stop> [1] Enter an integer, 0 to stop> [2] Enter an integer, 0 to stop> [3]...
On python how do i prompt a user to enter a number but the program is...
On python how do i prompt a user to enter a number but the program is only inclusive for a certain range. For example, prompting the user to enter a number (inclusive with integers between 0 and 10)?
Create a simple addition calculator in Java. The program should prompt the user to enter 2...
Create a simple addition calculator in Java. The program should prompt the user to enter 2 integers, then adds the numbers and prints the result. Make sure the program includes appropriate exception handling in case the user does not enter appropriate integer values.
JAVA IDE NETBEANS Create a program that will prompt the user to enter 20 numbers using...
JAVA IDE NETBEANS Create a program that will prompt the user to enter 20 numbers using any looping statement. Store it in a 2-dimensional array. Display all the numbers in a table format. Determine which numbers are odd and which numbers are even (include their array index) need some help with codes
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT