Though I don't know MIPS assembly language I know ARM pretty well, and I'm confused by the question. So, .text usually contains instructions, and .data contains data. A C struct declaration is neither of these things. I guess you're asking how to allocate memory for it? What do you have so far?
I scoured around for some documentation of how syscall 9 behaves on the MARS simulator, but doesn't seem to be very helpful. I don't think there is any guarantee of alignment of the returned address (though as has been said, it wouldn't be unreasonable to expect it to be quite well aligned e.g. on a page boundary).
The MIPS ABI says that structures should be as aligned as their most aligned member. So this'll come down to the size of the pointer -- is it MIPS32 or MIPS64? Suppose it's a 64-bit pointer, then your struct needs to be 8 bye aligned and will look like:
Code:
Offset
0 int data;
4 4 bytes padding
8 struct node *next;
And will have a total size of 16 bytes.
Assuming the address returned from the syscall isn't aligned, you can align it to 8 bytes like (I don't know MIPS asm at all so check this, I just looked at a reference briefly)
Code:
# address in $t0
add $t0,$t0,7
li $t1,7
nor $t1,t1,t1
and $t0,$t0,$t1
No idea if that is remotely legal MIPS Given the address, add 7 to it, then AND it with NOT(7) (0xffffffff8) to clear the bottom 3 bits. Bottom 3 bits clear means 8 byte aligned. The addition makes sure you don't end up with an address below the one you allocated.
So then you'll have an aligned address in $t0.
Code:
lw $t1 ($t0) # load word from address in $t0 and put in $t1, that's your "int data"
ld $t2 8($t0) # Eww. I've never appreciated ARM syntax so much. Load doubleword from address ($t0 + 8) and put in t2, that's your next pointer
And so on and so forth. Adjust appropriately if you're on a 32-bit system with 32-bit pointers.
I don't think you need/want to do anything in the .data segment. I'm not sure -- MIPS may handle this differently, but on ARM if translating from C, you'd put your initialised global variables in there. So if you had:
Code:
nodeL initnode = {5, NULL};
You'd put it in the .data section:
Code:
.data
.align 3
initnode:
.word 5
.space 4 # or .align 3
.double 0
What are you trying to accomplish anyway? If you're trying to learn assembly language I'd definitely not recommend doing it by directly translating C. I'd say start from a problem (e.g. "read a string, invert the case of all the characters and print it") and try to solve it.
If you have some C you want to run, get a compiler and a simulator that lets you load compiled binaries.
If you want to understand the relation between C and MIP assembler, get a compiler and a disassembler (e.g. GNU tools have gcc and objdump) and have a play, look at the output, maybe copy some of it into MARS. Wouldn't help you with this as a call to malloc is just a call to malloc