Warm tip: This article is reproduced from serverfault.com, please click

MIPS architecture padding

发布于 2020-12-03 16:11:37

How do data types get allocated in stack in MIPS architecture? If i have 2 char and 1 int data, is stack going to allocate them in 8 byte form(2 chars are in same memory segment and 1 int is in another memory segment) or 12 byte form(memory segment for each chars and 1 memory segment for int)? I am trying to understand 32 bit MIPS architecture.

Questioner
Bcrx
Viewed
11
Erik Eidt 2020-12-04 00:37:57

To the question, it matters if the data types being allocated are for local variables vs. for parameter passing.

For locals you can allocate whatever you want as long as the int is aligned on 4 byte boundary.  The total stack allocation is rounded up to 8 bytes (though some don't bother with this, e.g. for homework, and, is only strictly necessary if your function calls other functions that may rely on the expected 8 byte alignment of the stack.)

For parameters you should follow the documented calling convention — there are several so you have to know which you're working with.  See here to see some of them; look for "MIPS EABI 32-bit Calling Convention" and/vs. "MIPS O32 32-bit Calling Convention".

What they have in common is that the first four parameters are passed in registers, which effectively means that chars take a full 32-bit word; char parameters passed on the stack also follow that form, so take a full 32-bit word each.