Exam3 Key Summer13
Exam3 Key Summer13
L
_____ actual parameter A. read-only memory region for initialized data
K formal parameter
_____ B. write-only memory region for initialized data
C .data section
_____ C. read-write memory region for initialized data
A .rodata section
_____ D. copy value of actual parameter into space allocated for
formal parameter.
J .text section
_____
E. copy address of actual parameter into space allocated for
G "stack" section
_____ formal parameter
H "heap" section
_____ F. copy value of actual parameter into space allocated for
O .align 4 formal parameter, and copy final value of formal
_____
parameter back into actual parameter
M a00, a01, a02, ...
_____ G. memory region for stack frames
N a00, a10, a20, ...
_____ H. memory region for dynamically allocated data
E call-by-reference
_____ I. memory region for assembly language source
F call by value-result
_____ J. memory region for machine instructions
K. parameter defined in subroutine header
L. parameter passed to subroutine from caller
M. row-major memory order for an array
N. column-major memory order for an array
O. memory alignment directive for words
P. directive to move location counter to 4
11. Show the addressing arithmetic expression for calculating the byte address of element p[i] in an array
declared in C as "int p[200]". Note that for the purposes of this question, sizeof(int) is 4. (No ARM code is
necessary). Use the address "p" as the base address of the array and use 0-origin indexing.) (4 pts.)
p + 4*i
void main(void){
int d = 1,
int e;
e = subr(a, d);
}
Show final values after calls to subr() for the variables listed below, by column, according to the
specified parameter passing methods. (18 pts. total)
14. a 20
________ 8
________ 23
________
1 3 3
15. d ________ ________ ________
31 31 49
16. e ________ ________ ________
17. Consider the following ARM code for the subroutine fn2: (3 pts each)
.global fn2
fn2:
add sp, sp, #0
mov r5, sp
ldr r6, [r0]
add r3, r1, r3
ldr r0, [r2, #40]
add r0, r0, r3
reference
a. The parameter in r0 is passed by ______________________. How can this be observed from the ARM
code?
a load instruction was needed to access the value
value
b. The parameter in r1 is passed by ______________________. How can this be observed from the ARM
code?
it is used directly; no extra load
18. Give the ARM code for the following C functions. Use m4 defines to provide symbolic register names and
use these symbolic names in your code. (20 pts.)
.global set_a
.type set_a, %function
set_a:
push {r4, lr}
.global init_a
.type init_a, %function
init_a:
push {r4, r5, lr}
mov r4, #0
cmp r4, r1 @ check to see if r4 == n
bge finish
loop:
mov r5, r4, lsl #2
str r2, [r0, r5]
finish:
pop {r4, r5, pc}
19. Give ARM assembly code that implements the following C function: (15 pts.)
.global descend
.type descend, %function
descend: @ addr a is in r0
@ addr b is in r1
push {lr} @ save return address
ldr r2, [r0] @ move a into r2
ldr r3, [r1] @ move b into r3
cmp r2, r3
bge done