Question

In: Computer Science

Write a MIPS assembly language program to read an arbitrary number of integer pairs from a...

Write a MIPS assembly language program to read an arbitrary number of integer pairs from a file. Each pair will then be multiplied together with the results being accumulated (added together) forming a sum-of-products operation.

Submit your report and code here.

Solutions

Expert Solution

Using a text editor create the following program file and experiment with the different features of the MIPS simulator. All MIPS assembly language source code files must be saved as text only. the algorithm used here sums the integers in reverse order.

Program Name: Sum of Integers

Programmer:    YOUR NAME

Date last modified:

# Functional Description:

# A program to find the Sum of the Integers from 1 to N, where N is a value

# input from the keyboard.

# Pseudocode description of algorithm:

# main:    cout << “Please input a value for N”

#        cin >> v0

#        If ( v0 <= 0 ) stop

#        t0 = 0;

#        While (v0 > 0 ) do

#            {

#            t0 = t0 + v0;   

#            v0 = v0 - 1;

#            }

#        cout << t0;

#        go to main

# Cross References:

# v0: N,   

# t0: Sum

        .data

prompt:    .asciiz “\n Please Input a value for N= ”

result: .asciiz “ The sum of the integers from 1 to N is ”

bye:        .asciiz    “\n **** Adios Amigo - Have a good day ****”

        .globl    main

        .text

main:   

        li    $v0, 4 # system call code for Print String

        la    $a0, prompt # load address of prompt into $a0

        syscall # print the prompt message

li    $v0, 5 # system call code for Read Integer

        syscall # reads the value of N into $v0

blez    $v0, end # branch to end if $v0 < = 0

        li    $t0, 0 # clear register $t0 to zero

loop:       

        add     $t0, $t0, $v0 # sum of integers in register $t0

        addi    $v0, $v0, -1 # summing integers in reverse order

        bnez    $v0, loop # branch to loop if $v0 is != zero       

        li    $v0, 4 # system call code for Print String

        la    $a0, result # load address of message into $a0

        syscall # print the string

li    $v0, 1 # system call code for Print Integer

move    $a0, $t0 # move value to be printed to $a0

        syscall # print sum of integers

        b     main # branch to main

end: li    $v0, 4 # system call code for Print String

la    $a0, bye # load address of msg. into $a0

        syscall # print the string

        li    $v0, 10        # terminate program run and

        syscall            # return control to system


Related Solutions

Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results). (Make sure you use comments next to each line to describe what actions you are taking in your code. )...
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language to transpose a square integer matrix in code
Write a program in MIPS assembly language to convert an ASCII number string containing positive and...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and negative integer decimal strings, to an integer. Your program should expect register $a0 to hold the address of a nullterminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character appears anywhere in the string, your program should stop with...
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT