You should know the basic C/C++ notations related to arrays,
structures, pointers, etc. The following is a list of examples:
Structure definitions, assuming S is the name of a
struct in C, m is a member of the structure
&(S.m) - &S: the number of bytes between the
first byte of member m from the beginning of a
struct S
Local variables or parameters, assuming x is a local
variable or a parameter
&x - SP: the number of bytes between the first byte
of x and where the stack pointer points to
Variables, assuming x is a variable
&x the address of variable x
x the value/content of variable x
Member access of an instance of a structure, assume p
is a pointer to a structure, s is a structure,
m is a member of the struct definition
p->m: the value/content of member m of
the structure that is pointed to by p
s.m: the value/content of member m of the
structure s
&(p->m): the address of member m of
the structure that is pointed to by p
etc.
Pointers, assume p is a pointer:
*p: the value/content that p points
to
Return value:
retval: the return value of the most recent function
invocation
Return address:
retaddr: the location in the caller that the current
function should return to in order to continue program execution
2 More examples
b==&((*p)->m): register B is the address of
member m of the structure that is pointed to by an
anonymous pointer that, in return, is pointed to by p
c==p->n->m): register C is the value/content of
member m of a structure that, in return, is pointed to by
member n of a structure that is pointed to by
p
a==&v - SP: register A is the number of bytes
between the first byte of v and where the stack pointer
points to
b==retAddr: register B is the return address to
continue execution in the caller
a==f(a,b,c): register A is the return value of the
function invocation f(a,b,c)
3 General memory use
Reading from and writing to a memory location requires an “indirect”
(aka dereference) access. This means the address needs to be in one of
the 4 registers in the register bank.
The only exception is the ldi instruction. It also
reads the immediate value from memory, but the location is fixed
relative to the address of the opcode, and therefore does not need a
register to point to the location.
All parameters and local auto variables are in a call
frame.
A call frame is created for each invocation of a function
to provide a context for the function to operate.
Everything in a call frame can be accessed via an offset from where
the stack pointer points to immediately after the allocation of local
variables.
The start address of a call-frame is not fixed, it depends on the
state of the stack when a function is invoked (called).
The ordering of items in a call frame depends on the order of being
pushed and/or allocated. This, in return, depends on the caller-callee
agreement.
The offset of items in a call frame from where the stack pointer
points to can “shift” as more values are pushed on the stack. This
“shift” must be manually accounted for since the assembler does not
track the additional pushes and/or allocations.
Parameters are pushed by the caller in the fashion of “last argument
pushed first.”
The return address is pushed after all arguments are pushed (all by
the caller).
At the entry point (label) of a function, the return address is
always pointed to by the stack pointer.
Local variables are allocated by a function (being called). The
ordering of the local variables can be arbitrary as long as
there are enough bytes allocated, and
the access to the local variables is consistent (the same offset to
the same variable) in the function.
In TTPASM, a structure is a contiguous region of memory where
it is partitioned based on the members,
the partitioning is based on the ordering of the members,
and there is no gap between members.
The first member of a structure shares the same address as the
structure itself.
In TTPASM, an array is a contiguous region of memory where
each element has the same size (based on the type), and
there is no gap between elements.
The first element of an array shares the same start location as the
entire array.
The value of a pointer is an address of something.
A pointer variable or parameter has its own address because every
variable or parameter lives in memory.