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 in c plus plus Write a program that computes the sum of the odd numbers...
write in c plus plus Write a program that computes the sum of the odd numbers and the sum of the even numbers between two values a and b. For example a=1 and b=10
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
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...
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
Write a program in java which store 10 numbers and find the sum of odd and...
Write a program in java which store 10 numbers and find the sum of odd and even numbers. Create a program that uses a two dimensional array that can store integer values inside. (Just create an array with your own defined rows and columns). Make a method called Square, which gets each of the value inside the array and squares it. Make another method called ShowNumbers which shows the squared numbers. Write a program in java which has an array...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT