wonderingdev
wonderingdev

Reputation: 1181

MIPS: What's the size of integer constants in MIPS?

My question is: What is the size of integer constants in MIPS?

Here I found how they are used.

If I have such a constant defined in my data segment and I want to calculate the size of the data segment, what size do I take for this constant: size of word, byte, half,..?

Here's a data segment example:

.data
array: .word 1, 2, 3
LEN = 2                ; Here's the constant

The size of data segment is: 3 * 32(bit) + ?(bit)

Thank you in advance!

Upvotes: 2

Views: 4874

Answers (1)

gusbro
gusbro

Reputation: 22585

I assume you are calling constants to "equates".

Constants do not occupy space in the data segment, whenever used as an operand they will be replaced by their expression and the size should match that of the operand, so in your example the data segment would be using 4*3 bytes = 12 bytes (96 bits).

For example if you write in MARS simulator

.data
 array: .word 1,2,3
.eqv LEN 2
.eqv LARGE_VALUE 20000
 buffer: .space LARGE_VALUE

then you can use identifier LEN as a substitute for 2, e.g.

 li $a1, LEN
 li $a2, LARGE_VALUE

In this case, LEN will be a 16 bit immediate when assembling the first instruction, and the assembler will emit code to do a 32-bit load for the second pseudo instruction. The buffer defined in data segment will be 20000 bytes (as defined by eqv LARGE_VALUE)

Upvotes: 1

Related Questions