Question

In: Computer Science

Write a MIPS Assembly program that computes the sum of all the odd numbers from 1...

Write a MIPS Assembly program that computes the sum of all the odd numbers from 1 ..99 and print out the answer.

Solutions

Expert Solution

main:     
                li      $v1, 99     # initialized v1 to 99
                li      $t1, 0          # initialized t1 to 0
loop:           
                add     $t1, $t1, $v1   # sum of odd numbers in register $t0
                addi    $v1, $v1, -2    # summing of odd numbers in reverse order
                bnez    $v1,  loop              # branch to loop if $v0 is != zero              
                li      $v1, 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 program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored...
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored in a 16-bit integers array. The size of the array is provided in a separate variable. Use the following design: Sum = 0 FOR i = 0 TO SizeOfArray - 1     IF Arr[i] % 2 = 1           Sum = Sum + Arr[i]     END IF END FOR
Write a MIPS assembly program to calculate the Fibonacci numbers from 1..n using the recursive method....
Write a MIPS assembly program to calculate the Fibonacci numbers from 1..n using the recursive method. The definition of a Fibonacci number is F(n) = F(n-1) + F(n-2). The implementation must follow the following guidelines: Prompt the user for a number n Allocate heap memory to hold the exact number of elements in the Fibonacci sequence for n Implement recursive Fibonacci method as a subprogram Print the Fibonacci sequence array
Write a MIPS program that asks the user for 2 numbers. Output the sum of the...
Write a MIPS program that asks the user for 2 numbers. Output the sum of the 2 numbers. The difference between the 2 numbers (num1-num2) and (num2-num1) The value that is 305 more than the 1st number. The value that is 305 less than the 2nd number
Use a For loop to compute the sum of all the odd numbers from 1 through...
Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500. Print your name 7 times using a While loop. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"}; Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop. Reverse the logic for zyBook Challenge activity 4.6.1 (Nested loops: Indent text) so that the first line is indented userNum...
1. Write MIPS assembly code to sum “n” positive integers. Forexample, n=5, read 5 numbers...
1. Write MIPS assembly code to sum “n” positive integers. For example, n=5, read 5 numbers in memory (“.data” section) and add them together. 2. Write MIPS assembly code to calculate N-factorial. Read n from the memory. (Hint: use “.data” to define the content in a memory location)
Q1) Write programs with iterators that computes: • The sum of all even numbers between 2...
Q1) Write programs with iterators that computes: • The sum of all even numbers between 2 and 100 (inclusive). • The sum of all squares between 1 and 100 (inclusive). • The product of all powers of 2 from 20 up to 220 . • The product of all odd numbers between a and b (inclusive), where a and b are inputs. sum would be 3 + 7 + 7 = 17.) Q2) Recall the Fibonacci sequence: 1, 1, 2,...
MIPS Assembly program: Accept N numbers from the user and sort the N numbers using any...
MIPS Assembly program: Accept N numbers from the user and sort the N numbers using any sorting algorithm. Print both the sorted array and unsorted array. N should be greater than or equal to 10.
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by 7, and compute the average of those numbers, print both the sum and the average with appropriate messages to the screen. Run the program. Capture the console output. Put the program code and console output at the end of your text file,
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS)...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS) which works as a simple calculator. The program will get two integer numbers, and based on the requested operation, the result should be shown to the user. a. The program should print a meaningful phrase for each input, and the result. i. “Enter the first number” ii. “Enter the second number” iii. “Enter the operation type” iv. “The result is” b. The user should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT