3

I'm new in MIPS and trying to teach myself using this book. I'm trying to learn data directive and what are the difference between these three :

list:   .word 0:3
list:   .word 3
list:   .word

But I didn't find any clear document/reference.

Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Node.JS
  • 1,042
  • 6
  • 44
  • 114

1 Answers1

4
list:   .word 0:3

Will reserve 3 words and set each to the value 0. This would be similar to:

int list[3] = {0, 0, 0};

Or

list:   .space 12

(In which case, the value is implicitly 0).

The 0 in '0:3' could have very well be any other value. For example:

list:   .word 'X':3
# or
list:   .word 88:3

When the number of elements is missing, it's simply the value of the word

list:   .word 3

Which is similar to

int list = 3;

The last one,

list:   .word

Will likely cause assemblers to complain for the missing operand.

Wiz
  • 2,145
  • 18
  • 15
  • Thank You and Perfect Answer. But one more question: list: .word 0:3 is a Dynamic memory allocation or Static? How about stack pointer ($sp)? – Node.JS Jul 28 '13 at 14:47
  • 2
    @Hooman That's static. It's all static in fact. The .data or .rdata are used mainly for static data setup when your program starts up. Just like the C's `static` keyword when outside of any function. Dynamic memory, typically via `new` or `malloc()` are typically allocated via a system call (Look up `syscall`). Memory allocated on the stack are your typical C automatic variables. For example `void foo() { int x; }` here x is an automatic variable that will be allocated on the stack. – Wiz Jul 28 '13 at 15:50