Professional Documents
Culture Documents
15 513 Written Assignment 3
15 513 Written Assignment 3
Written Assignment 3
June 22, 2021
1 Question 1
Question: What are caller- and callee-saved registers? Briefly compare the
similarities and differences between the two.
1.1 Similarities
Caller- and callee-saved registers are registers, standing at the highest level
(L0) of the memory hierarchy. CPU can access registers in a single clock
cycle.
1.2 Differences
The distinction between caller- and callee-saved registers can be observe lit-
erally from their names. Caller represents the procedure that calls another
procedure. Callee represents the procedure that is being called by another
procedure.
A caller-saved register can be modified by any function, meaning that the
caller function must first save the data of the caller-saved register before it
makes the call, i.e., caller has the responsibility to save the data of caller-
saved registers. On the other hand, callee-saved registers must preserve the
values before and after the callee function, i.e., callee has the responsibility
to preserve the data of caller-saved registers. This can be done by either not
modifying the register at all or by pushing the original value on the stack,
altering it, and then popping the old value form the stack before returning
[1].
1
2 Question 2
Question: Think about following structure
1 struct a {
2 char c [ 3 ] ;
3 size t y;
4 int z ;
5 };
Using proper alignment, how much space does this struct take up in mem-
ory? Describe a way to save space with this struct and state how much
space is saved. How would accessing values differ with or without padding
in data structures like structs and arrays? Why is the padding used in these
cases important?
c[3] y z (1)
|{z} |{z} |{z}
3 bytes 8 bytes 4 bytes
2
In this case, the struct only occupies 16 bytes. Through changing the order
of data fields in struct, 8 bytes are saved.
References
[1] Randal E Bryant, O’Hallaron David Richard, and O’Hallaron David
Richard. Computer systems: a programmer’s perspective. Vol. 2. Prentice
Hall Upper Saddle River, 2003.