Question

In: Computer Science

if I need to get the sum of 6 numbers, here is a C programming solution...

if I need to get the sum of 6 numbers, here is a C programming solution

int getSum(int number1, int number2, int number3, int number4, int number5, int number6);

and the function is:

int SUM;

sum = number1+number2+number3+number4+number5+number6;

return SUM;

this function is called in main, and the main looks like:

int totalSum;

totalSum=getSum(1,2,3,4,5,6);

while(1);

so how can I write this C programming code in ARM assembly code, can you please write the comment of each line so I can understand the code better, we only need to implement the function getSum(), which is called from the c code in main(). Please add some c code that is needed to call the function getSum().

Solutions

Expert Solution

The given C program is:

int getSum(int number1, int number2, int number3, int number4, int number5, int number6) {

    int SUM;

    SUM=number1+number2+number3+number4+number5+number6;

    return SUM;

}

main()

{

    int totalSum;

    totalSum=getSum(1,2,3,4,5,6);

}

The corresponding code in arm (arm64 gcc 6.4) assembly language is given below:

getSum:

        sub     sp, sp, #48 // stack space allocated

        str     w0, [sp, 28] // stores number 1

        str     w1, [sp, 24] // stores number 2

        str     w2, [sp, 20] // stores number 3

        str     w3, [sp, 16] // stores number 4

        str     w4, [sp, 12] // stores number 5

        str     w5, [sp, 8]  // stores number 6

        ldr     w1, [sp, 28]  // load number 1

        ldr     w0, [sp, 24]  // load number 2

        add     w1, w1, w0  // add numbers

        ldr     w0, [sp, 20] // load number 3

        add     w1, w1, w0  // add numbers

        ldr     w0, [sp, 16] // load number 4

        add     w1, w1, w0 // add numbers

        ldr     w0, [sp, 12] // load number 4

        add     w1, w1, w0 // add numbers

        ldr     w0, [sp, 8]  // load number 5

        add     w0, w1, w0 // add numbers

        str     w0, [sp, 44]

        ldr     w0, [sp, 44] // load number 6

        add     sp, sp, 48 //add numbers

        ret

main:

        stp     x29, x30, [sp, -32]!

        add     x29, sp, 0

        mov     w5, 6 //load 6

        mov     w4, 5 //load 5

        mov     w3, 4 //load 4

        mov     w2, 3 //load 3

        mov     w1, 2 //load 2

        mov     w0, 1 //load 1

        bl      getSum //call getSum()

        str     w0, [x29, 28] // final result

        mov     w0, 0

        ldp     x29, x30, [sp], 32

        ret


Related Solutions

I need C++ programming with output. I have tried other programming and it does not work....
I need C++ programming with output. I have tried other programming and it does not work. So please give me the one that actually works. Assignment 1 Design your own linked list class that works as a template class. It should provide member functions for appending, inserting and deleting nodes. The destructor should destroy the list. The class should also provide a member function that will display the contents of the list to the screen. The class should also provide...
Java Programming I need an application that collects the user input numbers into an array and...
Java Programming I need an application that collects the user input numbers into an array and after that calls a method that sums all the elements of this array. and display the array elements and the total to the user. The user decides when to stop inputting the numbers. Thanks for your help!
I need to write a c/c++ code to find the maximum sum in those possible combinations...
I need to write a c/c++ code to find the maximum sum in those possible combinations of arrays. There are N arrays with S elements. ex2: 4 arrays with 3 elements.We want to find the greater number in the same column of two arrays(may possible be three or four...arrays), and sum those greater number to find the greatest sum in all of the combinations in those 4 arrays, like: A: [50, 60, 70] B: [80, 40, 20] C: [30, 100,...
Note: I need a code and other requirement Note: programming language is c++ If you need...
Note: I need a code and other requirement Note: programming language is c++ If you need more information, please clarify what information you want. consider solving the equation sin(x) - e^(-x) = 0 write a computer program to solve the given equation using: 1- bisection method 2- fixed-point method 3- newton's intervals: {0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{8,9},{9,10} choose accuracy E = 10^(-5) Make sure you document your program Requirement : 1- Mathematical justification 2- algorithem description 3- code (program) with documentation 4-output: roots ,...
I am building a game in C programming language where I need to add objects of...
I am building a game in C programming language where I need to add objects of various length into a game board. The game board is 8X8 and we must account for the boundaries for the board and not go over them with our objects. The boards upper left corner is at 0x0 and we must return 1 if it fits and -1 if it does not fit. I have the following 2 functions to start with: ```int add_object_vert(int r,...
Python Programming Question: Objective: Sum of Numbers. Design a program with a loop that asks the...
Python Programming Question: Objective: Sum of Numbers. Design a program with a loop that asks the user to enter a series of positive numbers. The user should enter "0" (zero) to signal the end of the series. After all the positive numbers have been entered, the program should display their sum. The program should display the following: • Contain proper indentation. • Comments (Blocks or Lines). • Good Variables initializations. • Good questions asking for the parameters of the code....
I need this in C# please. Exercise #2: Design and implement a programming (name it NextMeeting)...
I need this in C# please. Exercise #2: Design and implement a programming (name it NextMeeting) to determine the day of your next meeting from today. The program reads from the user an integer value representing today’s day (assume 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, etc…) and another integer value representing the number of days to the meeting day. The program determines and prints out the meeting day. Format the outputs following the sample...
create two random numbers between 1 and 6. if when the sum of two numbers are...
create two random numbers between 1 and 6. if when the sum of two numbers are added togethere their sum is less than 5 or greater than 12, output to the console: "you win". if is not, output "you lose" C++
A die is thrown twice and the sum of the numbers rising is noted to be 6.
  A die is thrown twice and the sum of the numbers rising is noted to be 6. Calculate the is the conditional probability that the number 4 has arrived at least once?
Method calling in c# I need to write methods for calling the min and max numbers...
Method calling in c# I need to write methods for calling the min and max numbers using this code; Console.WriteLine("Calling highest method."); Console.WriteLine("Highest number is: {0}", highest(3)); Console.WriteLine("Calling lowest method."); Console.WriteLine("Lowest number is: {0}", lowest(3));
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT