Question

Write a MIPS (MARS) program that asks the user what he wants the sentinel to be...

Write a MIPS (MARS) program that asks the user what he wants the sentinel to be

enter numbers until the sentinel is entered.--do not save the entered numbers

output the sum of all the positive numbers

the sum of all the negative numbers

how many positive numbers were entered

how many negative numbers were entered

how many zeros were entered

output if the most "type" of numbers is positive, negative or zero

do not need to check for an invalid sentinel

may assume the counts for positive, negative, and zero will all be different.

check for an invalid sentinel and check for "types" being the same

use only add, addi,sub, li, la, syscall,all forms of branch, move (no functions)

be sure to comment

Sample runs:

Enter the sentinel value (may not be 0)999
Enter a Number: 1
Enter a Number: 0
Enter a Number: 0
Enter a Number: -2
Enter a Number: -2
Enter a Number: -2
Enter a Number: 999
Sum of positive numbers: 1 Sum of negative numbers: -6
There were 1 positive numbers, 3 negative numbers and 2 zeroes

there were more negative
program exiting

-- program is finished running --

Enter the sentinel value (may not be 0)999
Enter a Number: 1
Enter a Number: 0
Enter a Number: 0
Enter a Number: 0
Enter a Number: -2
Enter a Number: -2
Enter a Number: 999
Sum of positive numbers: 1 Sum of negative numbers: -4
There were 1 positive numbers, 2 negative numbers and 3 zeroes

there were more zeros
program exiting

Homework Answers

Answer #1

Please give positive ratings for my effort. Thanks.

ANSWER

.LC0:
        .ascii  "Enter the sentinel value (may not be 0)\000"
.LC1:
        .ascii  "%d\000"
.LC2:
        .ascii  "Enter a Number: \000"
.LC3:
        .ascii  "\012Sum of positive numbers : %d\000"
.LC4:
        .ascii  "  Sum of negative numbers : %d\000"
.LC5:
        .ascii  "\012There were %d positive numbers, %d negative numbers "
        .ascii  "and %d zeroes\000"
.LC6:
        .ascii  "\012\012There were more positive\000"
.LC7:
        .ascii  "\012\012There were more negative\000"
.LC8:
        .ascii  "\012\012There were more zeros\000"
main:
        daddiu  $sp,$sp,-64
        sd      $31,56($sp)
        sd      $fp,48($sp)
        sd      $28,40($sp)
        move    $fp,$sp
        lui     $28,%hi(%neg(%gp_rel(main)))
        daddu   $28,$28,$25
        daddiu  $28,$28,%lo(%neg(%gp_rel(main)))
        sw      $0,20($fp)
        ld      $2,%got_page(.LC0)($28)
        daddiu  $4,$2,%got_ofst(.LC0)
        ld      $2,%call16(printf)($28)
        move    $25,$2
        nop

        daddiu  $2,$fp,24
        move    $5,$2
        ld      $2,%got_page(.LC1)($28)
        daddiu  $4,$2,%got_ofst(.LC1)
        ld      $2,%call16(__isoc99_scanf)($28)
        move    $25,$2
        nop

        sw      $0,0($fp)
        sw      $0,4($fp)
        sw      $0,8($fp)
        sw      $0,12($fp)
        sw      $0,16($fp)
.L7:
        ld      $2,%got_page(.LC2)($28)
        daddiu  $4,$2,%got_ofst(.LC2)
        ld      $2,%call16(printf)($28)
        move    $25,$2
        nop

        daddiu  $2,$fp,20
        move    $5,$2
        ld      $2,%got_page(.LC1)($28)
        daddiu  $4,$2,%got_ofst(.LC1)
        ld      $2,%call16(__isoc99_scanf)($28)
        move    $25,$2
        nop

        lw      $2,20($fp)
        lw      $3,24($fp)
        beq     $2,$3,.L13
        nop

        lw      $2,20($fp)
        bgez    $2,.L4
        nop

        lw      $2,4($fp)
        addiu   $2,$2,1
        sw      $2,4($fp)
        lw      $2,20($fp)
        lw      $3,16($fp)
        addu    $2,$3,$2
        sw      $2,16($fp)
        b       .L7
        nop

.L4:
        lw      $2,20($fp)
        blez    $2,.L6
        nop

        lw      $2,0($fp)
        addiu   $2,$2,1
        sw      $2,0($fp)
        lw      $2,20($fp)
        lw      $3,12($fp)
        addu    $2,$3,$2
        sw      $2,12($fp)
        b       .L7
        nop

.L6:
        lw      $2,8($fp)
        addiu   $2,$2,1
        sw      $2,8($fp)
        b       .L7
        nop

.L13:
        nop
        lw      $2,12($fp)
        move    $5,$2
        ld      $2,%got_page(.LC3)($28)
        daddiu  $4,$2,%got_ofst(.LC3)
        ld      $2,%call16(printf)($28)
        move    $25,$2
        nop

        lw      $2,16($fp)
        move    $5,$2
        ld      $2,%got_page(.LC4)($28)
        daddiu  $4,$2,%got_ofst(.LC4)
        ld      $2,%call16(printf)($28)
        move    $25,$2
        nop

        lw      $4,8($fp)
        lw      $3,4($fp)
        lw      $2,0($fp)
        move    $7,$4
        move    $6,$3
        move    $5,$2
        ld      $2,%got_page(.LC5)($28)
        daddiu  $4,$2,%got_ofst(.LC5)
        ld      $2,%call16(printf)($28)
        move    $25,$2
        nop

        lw      $3,0($fp)
        lw      $2,4($fp)
        slt     $2,$2,$3
        beq     $2,$0,.L8
        nop

        lw      $3,0($fp)
        lw      $2,8($fp)
        slt     $2,$2,$3
        beq     $2,$0,.L8
        nop

        ld      $2,%got_page(.LC6)($28)
        daddiu  $4,$2,%got_ofst(.LC6)
        ld      $2,%call16(printf)($28)
        move    $25,$2
        nop

        b       .L9
        nop

.L8:
        lw      $3,4($fp)
        lw      $2,0($fp)
        slt     $2,$2,$3
        beq     $2,$0,.L10
        nop

        lw      $3,4($fp)
        lw      $2,8($fp)
        slt     $2,$2,$3
        beq     $2,$0,.L10
        nop

        ld      $2,%got_page(.LC7)($28)
        daddiu  $4,$2,%got_ofst(.LC7)
        ld      $2,%call16(printf)($28)
        move    $25,$2
        nop

        b       .L9
        nop

.L10:
        ld      $2,%got_page(.LC8)($28)
        daddiu  $4,$2,%got_ofst(.LC8)
        ld      $2,%call16(printf)($28)
        move    $25,$2
        nop

.L9:
        move    $2,$0
        move    $sp,$fp
        ld      $31,56($sp)
        ld      $fp,48($sp)
        ld      $28,40($sp)
        daddiu  $sp,$sp,64
        j       $31
        nop

IMAGE OF OUTPUT

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
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...
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
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.
Write a program that asks the user to type in ages. They will type a negative...
Write a program that asks the user to type in ages. They will type a negative age when they finish entering the ages. The program will print out the average of all of the ages and the oldest age entered. It should end with a newline. Sample output #1 Type a negative for age to exit Enter your age: 21 Enter your age: 22 Enter your age: 21 Enter your age: -8 The average age is: 21.33 The oldest person...
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 C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
Write a program that asks the user of a positive integer value. The program should use...
Write a program that asks the user of a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4,…,50. using namespace std;
C++ while loop Exercise Write a program that continues to ask the user to enter any...
C++ while loop Exercise Write a program that continues to ask the user to enter any set of numbers, until the user enters the number -1. Then display the total sum of numbers entered and their average. (note that you need to define a counter that counts how many numbers so the average = (sum/n) where n is your counter total. #include <iostream> using namespace std; int main() { int number, n=0, sum=0; cout << "Enter a number to start...
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...
In C++ write a program that prompts the user to enter two positive integers less than...
In C++ write a program that prompts the user to enter two positive integers less than 1,000,000,000 and the program outputs the sum of all the prime numbers between the two integers. Two prime numbers are called twin primes, if the difference between the two primes is 2 or -2. Have a program output all the twin primes and the number of twin primes between the two integers. NEEDED OUTPUTS FOR PROGRAM: Enter two positive integers <1,000,000,000: 1 100 -1...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT