I have a problem though, how can I keep track of all the students? maybe with a frame pointer ?
You don't need a frame pointer to keep track of all the students. Further, the problem of keeping track of them is not unique to their being struct's — you would have the same problem keeping track of many of integers. And further still, the problem of keeping track of many items is also not unique to assembly.
What you need is either a separate variable for each item (often impractical, especially if the number of items is variable), or, a data structure: a collection of some sort, e.g. an array or linked list, for example.
With a separate local variables in C each needs a different name, and, in assembly each would have a different offset/location in the stack frame. Stack space for all would be allocated in one instruction, and they all be referenced via their individual offset from the stack pointer.
A frame pointer can be used if you like, but since with MIPS the stack space for a function's stack frame is all allocated in one instruction in function prologue, the stack pointer doesn't otherwise move during the function's body — and that means that the individual variables remain at constant offsets from the stack pointer.
A frame pointer can be helpful if either:
- the machine doesn't do stack relative offsets well, but does frame pointer relative offsets easily, or,
- the machine requires frequent pushing and popping that move the stack pointer, which changes the offsets needed to access the same locations in the stack frame — a frame pointer remains constant regardless of pushing and popping. (Pushing and popping may be used for argument passing, and/or temporary storage if there are insufficient CPU registers, e.g. during expression evaluation.)
- A function dynamically allocate stack space, e.g. via C's
alloca
.
Broadly speaking, the first two do not apply to MIPS, so functions generally don't need a frame pointer.
Alternatively, you can use a data structure like an array to keep track of many items. The array itself needs to be referred to by a variable (in C, a name, and in assembly an offset) — but at least there's only one variable regardless of how many items to keep track of. And then you're down to indexing to access the individual elements. (Indexing involves computing the address of the elements, and depends on the size of the elements, but otherwise operates the same for an int array vs. a struct array.)