0% found this document useful (0 votes)
60 views5 pages

Exam3 Key Summer13

This document contains an exam for a computer architecture course. It includes multiple choice and short answer questions about concepts like parameter passing methods, stack frames, and ARM assembly code. The questions cover C programming language concepts like arrays and pointers as well as low-level computer architecture topics.

Uploaded by

Some
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views5 pages

Exam3 Key Summer13

This document contains an exam for a computer architecture course. It includes multiple choice and short answer questions about concepts like parameter passing methods, stack frames, and ARM assembly code. The questions cover C programming language concepts like arrays and pointers as well as low-level computer architecture topics.

Uploaded by

Some
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CPSC 2310 Name ______________________________________

Exam 3 – Summer II 2013


Points add to 105. You will be graded out of 100.

1. Matching. Indicate the letter of the best description. (3 pts. each)

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

12. Identify three items in a generic stack frame. (6 pts)

parameters, local variables, registers to save


13. Consider this program and subroutine

int a = 5; /* global variable */

int subr( int b, int c )


{
a = 4*a;
b = b + 3;
c = c + 2;
return( a + b + c );
}

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)

b: call by value b: call by value-result b: call by reference


c: call by value c: call by value-result c: call by reference

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.)

void set_a(int a[], int i, int j){ .global set_a


a[i] = j; .type set_a, %function
}

.global set_a
.type set_a, %function

set_a:
push {r4, lr}

mov r4, r1, lsl #2


str r2, [r0, r4]

pop {r4, pc} @ OR pop {r4, lr}


@ bx lr
Problem 18 continued

void init_a( int x[], int n, int val ){ ...


int i, sum = 0; .global init
for( i=0; i<n; i++ ){ init_a:
x[i] = val;
}
}

.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]

add r4, r4, #1


cmp r4, r1 @ check to see if r4 == n
blt loop

finish:
pop {r4, r5, pc}
19. Give ARM assembly code that implements the following C function: (15 pts.)

int descend(int *a, int *b)


{
if(*a < *b)
{
int temp = *a;
*a = *b;
*b = *a;
}
}

.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

str r3, [r0] @ store indirectly


@ into a
str r2, [r1] @ store indirectly
@ into b
done:
mov r0, #0
pop {pc}

You might also like