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 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...
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.
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter 10 numbers. 2. save those numbers in a 32-bit integer array. 3. Print the array with the same order it was entered. 3. Calculate the sum of the numbers and display it. 4. Calculate the mean of the array and display it. 5. Rotate the members in the array forward one position for 9 times. so the last rotation will display the array in...
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even...
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even number and continue to do so until they enter the given QUIT condition. The prompt for the user to enter a number is written as follows: "Enter an even number or [QUIT] to quit:" The quitting condition in this case will be the number 999. If the number they entered was an even number, output the message "Good job!" Otherwise, output the message "[number]...
Write a program that asks the user to enter an odd number and prints out a...
Write a program that asks the user to enter an odd number and prints out a triangle pattern. For example, if the user enters 5, the output is note: There is one space between the numbers in each line 1 3 5 1 3 1 If the user enters 9 the output is: 1 3 5 7 9 1 3 5 7 1 3 5 1 3 1 program language: C++
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT