Studio 13: Final Review (Optional)


This optional studio is review material for the final exam. The TAs are here to help today, but no need to checkout.


By the end of this studio, you should know:

  • what to expect on the final exam

Studio organization

As a review, this studio is organized around the set of subjects we have covered since the second midterm exam. The exam is not intended to be comprehensive, yet returning to studios 4 and 9 and reviewing that material is still a good idea.

Each section will have some review questions, some pencil and paper style, some expecting you to author some code. For the questions where you are authoring code, note that exam questions that ask you to author code will by necessity be short.

Do not feel obligated in any way to do these in order. Jump around and focus on the ones that will give you the most benefit in terms of preparation for the final exam.

Data representation in memory

  1. On an AVR machine (i.e., the Arduino platforms we are using this semester), memory locations each contain one byte. When the 16-bit integer 0x1234 is stored in location 0x0050, this really implies that the literal value actually stored in location 0x0050 is ___________ and the literal value actually stored in location0x0051 is ___________.

  2. If a byte array foo is declared as

    byte foo[3] = {0x00, 0x11, 0x22};

and the address of foo is 0x200, what are the addresses of foo[0], foo[1], and foo[2]? What address will be accessed if the Arduino program makes reference to foo[3]?

Register usage

  1. What value is typically stored in register r1?

  2. What register pair is used to store a 2-byte return value from a function?

  3. For each of the following registers, is it a caller-save register (sometimes referred to as call-used) or a callee-save register(sometimes reffer to as call-saved)? r10, r15, r20, r25, r30

Assembly language

No, don’t panic. The final exam will not expect you to author a complete program of quite this complexity, and you will have access to the manual pages for whatever assembly language instructions are needed.

However, the best way to prepare is still to author code.

Given the following C code, provide an equivalent assembly program. You may assume that the size of an int is 16 bits. You are free to allocate i and sum either to registers or to memory during the execution of the loop, but please store the result in the variable result at the end. Provide appropriate comments in your assembly code.

const int n = XX; // n is the input value, give it a value
unsigned char i;  // when allocating space for i, you may assume n < 256
int sum;          // make sure that sum is two bytes
int result;       // result is definitely two bytes

sum = 0;          // write assembly language code for this line and the next 4 lines
for (i=0; i<n; i++) {
	sum = sum + i;
result = sum;

The first thing to do is simply execute the above code in Arduino C. Then author the last 5 lines in assembly language. Obviously, add Serial.println() statements as needed to see what is going on.

Finish up

If you haven’t yet done so, it’s a good idea to review the material from the two midterm exams as well. Remember, it is not a comprehensive final, but some material definitely builds on material from earlier in the semester.