Search code examples
assemblymipsmips32

Data section and text section in MIPS


I'm new to MIPS and I found that mostly we have to define a data section and a text section. I can understand that as it's just like to define a variable and to assign instructions. But why is writing ".data" and ".text" necessary? Is it possible to write code in MIPS without literally writing down ".data" and ".text"? For example, when I'm writing a program that only plays with registers, I don't even need to define anything in the data section now; why do I bother to write ".data"? And maybe I can neglect ".text" in this case as well?


Solution

  • There's no need to create a .data section if you're not using one.

    Whether you need to explicitly create a .text section is assembler-dependent. For example, if you're using QtSPIM it seems to default to assembling into the .text section (but you still need to specify a global main label since QtSPIM's startup code contains a jal main instruction).