Question

In: Computer Science

Write a MIPS assembly program that calculates the sum of all the elements in the following...

Write a MIPS assembly program that calculates the sum of all the elements in the following array: int array[10]={12,21,3,40,15,6,17,8,29,10}

Solutions

Expert Solution

MIPS Code:

main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 48
        mov     DWORD PTR [rbp-48], 12
        mov     DWORD PTR [rbp-44], 21
        mov     DWORD PTR [rbp-40], 3
        mov     DWORD PTR [rbp-36], 40
        mov     DWORD PTR [rbp-32], 15
        mov     DWORD PTR [rbp-28], 6
        mov     DWORD PTR [rbp-24], 17
        mov     DWORD PTR [rbp-20], 8
        mov     DWORD PTR [rbp-16], 29
        mov     DWORD PTR [rbp-12], 10
        mov     DWORD PTR [rbp-4], 0
        mov     DWORD PTR [rbp-8], 0
.L3:
        cmp     DWORD PTR [rbp-8], 9
        jg      .L2
        mov     eax, DWORD PTR [rbp-8]
        cdqe
        mov     eax, DWORD PTR [rbp-48+rax*4]
        add     DWORD PTR [rbp-4], eax
        add     DWORD PTR [rbp-8], 1
        jmp     .L3
.L2:
        mov     eax, DWORD PTR [rbp-4]
        mov     esi, eax
        mov     edi, OFFSET FLAT:_ZSt4cout
        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
        mov     eax, 0
        leave
        ret
__static_initialization_and_destruction_0(int, int):
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], edi
        mov     DWORD PTR [rbp-8], esi
        cmp     DWORD PTR [rbp-4], 1
        jne     .L7
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L7
        mov     edi, OFFSET FLAT:_ZStL8__ioinit
        call    std::ios_base::Init::Init() [complete object constructor]
        mov     edx, OFFSET FLAT:__dso_handle
        mov     esi, OFFSET FLAT:_ZStL8__ioinit
        mov     edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
        call    __cxa_atexit
.L7:
        nop
        leave
        ret
_GLOBAL__sub_I_main:
        push    rbp
        mov     rbp, rsp
        mov     esi, 65535
        mov     edi, 1
        call    __static_initialization_and_destruction_0(int, int)
        pop     rbp
        ret

If you have any doubts, feel free to ask

Happy learning


Related Solutions

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.
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
Write a MIPS assembly language program to solve the following problem: For a set of integers...
Write a MIPS assembly language program to solve the following problem: For a set of integers stored in an array, calculate the sum of the even numbers and the sum of the odd numbers. The program should store these numbers in memory variables: evenSum and oddSum. Numbers should be read from the array one at a time with a zero value (0) being used to signal the end of data in the array.
I need a MIPS Assembly program that "Display the elements of the linked list in reverse...
I need a MIPS Assembly program that "Display the elements of the linked list in reverse order." It needs subprogram and those subprogram does not have t registers.
Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
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...
Write a program in MIPS Assembly. This program will ask the user to enter 20 numbers....
Write a program in MIPS Assembly. This program will ask the user to enter 20 numbers. The program will store these numbers in an array in memory (sequential memory locations). It will then print out the list of numbers in three different formats: The numbers will be printed each on a separate line. The numbers will be printed on a single line, with spaces between the numbers. The program will ask the user to enter a number n. The program...
Write a program in C++ that calculates the sum of two fractions. The program should ask...
Write a program in C++ that calculates the sum of two fractions. The program should ask for the numerators and denominators of two fractions and then output the sum of the two fractions. You will need to write four functions for this program, one to read the inputted data, one to calculate the sum of the two fractions, one to find the Greatest Common Divider (GCD) between the numerator and denominator and a function that will display the end result....
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Using MIPS assembly language In this program, you should define an array of 10 elements in...
Using MIPS assembly language In this program, you should define an array of 10 elements in your data segment with these values: ? = {11, 12,−10, 13, 9, 12, 14, 15,−20, 0} a. Write a function which finds the maximum value of this array. b. Write another function which calculates the summation of this array. c. Call these functions in your main program, and print the outputs of these functions to the user i. “The maximum is 15” ii. “The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT