Consider the following portion of a C procedure: int *MyProc(int a, int b, char
ID: 3570505 • Letter: C
Question
Consider the following portion of a C procedure:
int *MyProc(int a, int b, char *c, char *d, int e, int f) {
int i, j, k, n;
int A[65];
...procedure body...
}
Assume that the standard Nios II register usage conventions are used, and the assembly code that was generated uses a frame pointer when making a procedure call. Furthermore, assume that the body of the function uses registers r8 through r20, MyProc calls another procedure, and i, j, k, and n are stored on the stack.
1.) In the prologue of the procedure, the stack pointer is adjusted using an addi instruction to make room for all the values of the stack frame. What decimal value would you expect to be used to make this adjustment?
I am trying to get a beginner grasp on the entire concept of how the stack works, and how to properly use it. This is a question I found on a previous test for the course I am taking. The answer is supposed to be -304
Explanation / Answer
Data objects
Instruction Set Size
(32 bit = 4 byte)
count
size*count
A[]
4
65
260
i,j,k,n
4
4
16
ra register
4
1
4
r15-r20 register
4
6
24
Total Decimal Value
304
Note: r8 - r14 used for 7 arguments, therefore excluded
All instructions are 32 bit, therefore all will require 4 bytes.
The logic is simple for all the data items it will require instruction address.
In the first row of the table I have mentioned all the data items in MyProc procedure which will be used.
Excluded the data item which are signatures of myproc, i.e. 6 arguments of proc and 1 proc address itself
The final list is as below:
* Remaining registers are r15 to r20 would be used by proc.
* ra would be return address.
* A[] array would be used
* ijkn variables would be used.
Data objects
Instruction Set Size
(32 bit = 4 byte)
count
size*count
A[]
4
65
260
i,j,k,n
4
4
16
ra register
4
1
4
r15-r20 register
4
6
24
Total Decimal Value
304
Note: r8 - r14 used for 7 arguments, therefore excluded