(a) How is the stack initialized? (b) When does stack underflow and stack overfl
ID: 2990337 • Letter: #
Question
(a) How is the stack initialized?
(b) When does stack underflow and stack overflow occur?
(c) What is the effect of the following set of instructions?
PUSH {R1}
PUSH {R2}
POP {R1}
POP {R2}
2. Convert the following C code to ARM assembly. Assume that R0 points to a[0], R1 points to b[0]and R2 points to c[0]. Try to use as few lines of code as possible. (Note: integers are 32 bits long.)
int a[10], b[10], c[10];
for(i=0; i<10; i++){
a[i] = b[i]+ c[i];
}
3. Convert the following C code to ARM assembly. Assume the following variable assignments: R0 = a, R1 = v, R2 = x, R3 = y, R4 = z. Strive for code efficiency.
int a, v, x, y, z;
switch (a) {
case 1:
v = x + y;
break;
case 2:
v = x + z;
y = y + 2;
break;
case 3:
v = x + y + z;
y = v
Explanation / Answer
Hello Dear,
The question is too long. I will answer only a few of them.
(b) A stack underflow occurs when we attempt to pop an element out of an empty stack.
And, a stack overflow occurs when we attempt to push an element into a stack that is already full.
(c) PUSH {R1} will push content of R1 into the stack.
PUSH {R2} will push content of R2 into the stack.
POP {R1} will pop the last pushed element out of the stack and save in R1.
POP {R2} will pop the stack and save in R2.
Thus, the contents of R1 and R2 are interchanged.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.