



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




label instruction comment
CostTo115: addi $5, $0, 4 # count equals run - 1
lw $2, Array($3) # load initial weight
Loop: add $3, $3, 44 # adjust for next square
lw $1, Array($3) # load weight add $2, $2, $1 # add to sum addi $5, $5, -1 # next loop? bne $5, $0, Loop # loop until done jr $31 # return to caller
Consider the following C fragment: int main() { int X = 100, Y = 255, Z = 1, A[] = {3, 5, 7}; int Foo(int, int *, int *); Z = Foo(X, &Y, A); printf("X = %d, Y = %d, A[0]=%d, A[1]=%d, A[2]=%d\n", X, Y, A[0], A[1], A[2]); return (Y); } int Foo(int P, int *Q, int V[]) { int Z = 35, W[] = {2, 4}; V[2] = W[0]; *Q = W[1]; P = P + Z; return(P); } Part A (15 points) Describe the current state of the stack before Foo returns to main. Fill in the unshaded boxes to show main’s and Foo’s activation frames. Include a symbolic description and the actual value (in decimal). For return addresses, show only the symbolic description; do not include a value. Label the frame pointer and stack pointer. address description value 9900 RA of main’s caller 9896 FP of main’s caller SP, main’s FP 9892 main’s RV (^9888) A[2] 7 2 (^9884) A[1] 5 (^9880) A[0] 3 (^9876) Z 1 (^9872) Y 255 4 (^9868) X 100 (^9864) RA of main (^9860) FP of main 9892 (^9856) V 9880 (^9852) Q 9872 (^9848) P 100 135
Foo’s FP 9844 Foo’s RV 135 (^9840) W[1] 4 (^9836) W[0] 2
SP 9832 Z 35 9828 9824
Below is a snapshot of heap storage. Values that are pointers are denoted with a “$”. The heap pointer is
with no gaps between objects. addr value addr value addr value addr value addr value addr value 6000 16 6032 12 6064 0 6096 16 6128 12 6160 0 6004 $6036 6036 0 6068 4 6100 $6080 6132 8000 6164 0 6008 0 6040 24 6072 $6148 6104 16 6136 2525 6168 0 6012 16 6044 $6036 6076 8 6108 5 6140 0 6172 0 6016 3 6048 16 6080 $6072 6112 $6004 6144 20 6176 0 6020 8 6052 20 6084 0 6116 8 6148 0 6180 0 6024 25 6056 $6120 6088 4 6120 $6132 6152 8 6184 0 6028 52 6060 0 6092 $6052 6124 24 6156 26 6188 0
Part B (8 points) List the address of the first data word in each object in the free list in order, starting with the head of the free list.
Free List : 6100, 6080, 6072, 6148
Part C (4 points) Based on the free list created in part B, if an object of size 22 bytes is allocated, what address will be returned using a first-fit allocation strategy?
Address : 6172
Part D (4 points) Based on the free list created in part B, if an object of size 7 bytes is allocated, what address will be returned using a first-fit allocation strategy?
Address : 6100
errors?
The data word above $6056 would be interpreted as the size of the object (20) and 20 bytes
would be freed, but they are not part of 1 contiguous object. They overlap with an object that’s
already on the free list. Reuse/changes to 1 object would cause unintended side effects to the other.
fragment by writing the optimized version (in C) to the right.
Briefly describe which standard compiler optimizations you applied: