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

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!
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....
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));
I NEED AN NLOGN OR LINEAR SOLUTION TO THIS PROBLEM! I NEED A FASTER SOLUTION THAN...
I NEED AN NLOGN OR LINEAR SOLUTION TO THIS PROBLEM! I NEED A FASTER SOLUTION THAN THE ONE GIVEN BELOW!! The solution below runs in quadratic time, I need one faster than this. I REPEAT I NEED A FASTER SOLUTION!! THE SOLUTION GIVEN BELOW IS TOO SLOW! Slow Solution: def predictAnswer(stockData, queries): stockData = [0] + stockData length = len(stockData) ans = [] for q in queries: l = q-1 r = q+1 flag = True while l > 0...
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio...
Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio development environment 3. To practice on writing a C# program Task 1: Create documentation for the following program which includes the following: a. Software Requirement Specification (SRS) b. Use Case Task 2: Write a syntactically and semantically correct C# program that models telephones. Your program has to be a C# Console Application. You will not implement classes in this program other than the class...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT