Question: Procedures often need to allocate memory for local variables and perhaps space to save registers so they can pass parameters to other procedures. This space

Procedures often need to allocate memory for local variables and perhaps space to save registers so they can pass parameters to other procedures. This space is allocated on the stack.
The general format of a stack frame is illustrated in Figure 3.25 on page 240 of the text.
(Figure 1)
The procedure may need to save registers so it can set up calls to other procedures that require different parameters. It may also require local variables that cannot be maintained in registers, and may also require space for more than six procedure parameters.
The space for a procedures stack frame is allocated by simply subtracting the appropriate value from %rsp. Individual elements of the frame are accessed by indexed references based on %rsp.
Consider the following function and the function that calls it:
long array_sum (int *p_array, int array_size)
{
long sum =0;
while (array_size--)
sum +=*p_array++;
return sum;
}
long caller (void)
{
int array[10];
int a_size =10;
long sum;
sum = array_sum (array, a_size);
return sum;
}
Below is the assembly code. Note that caller() allocated 48 bytes of stack for local variables, the 10-element integer array and apparently sum, even though its never stored in memory.
Drag the correct register to the appropriate location in the code below. Not all labels will be used.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!