0
votes

I am confused at some text in my computer organization book:

Let’s assume that A is an array of 100 words and that the compiler has associated the variables g and h with the registers $s1 and $s2 as before. Let’s also assume that the starting address, or base address, of the array is in $s3. Compile this C assignment statement:

g = h + A[8];

Although there is a single operation in this assignment statement, one of the operands is in memory, so we must first transfer A[8] to a register. The address of this array element is the sum of the base of the array A, found in register $s3, plus the number to select element 8. The data should be placed in a temporary register for use in the next instruction. Based on Figure 2.2, the first compiled instruction is

lw    $t0,8($s3) # Temporary reg $t0 gets A[8]

What is the base of Array A?

Computers divide into those that use the address of the leftmost or “big end” byte as the word address versus those that use the rightmost or “little end” byte. MIPS is in the big-endian camp. Since the order matters only if you access the identical data both as a word and as four bytes, few need to be aware of the endianess. (Appendix A shows the two options to number bytes in a word.)

Byte addressing also affects the array index. To get the proper byte address in the code above, the offset to be added to the base register $s3 must be 4 * 8, or 32, so that the load address will select A[8] and not A[8/4]. (See the related pitfall on page 160 of Section 2.19.)

Why is it 4*8? So if the offset is 32... does that mean the value in $s3 is -24? Can someone clarify this text?

What is the big end byte? What is leftmost?

1

1 Answers

1
votes

Why is it 4*8?

Because "A is an array of 100 words", and the size of a word is 4 bytes. So the word at index 8 will be located at offset 8*sizeof(word) == 8*4.

does that mean the value in $s3 is -24?

No, it doesn't say anything about the value in $s3.

What is leftmost?

0x12345678
   ^-- left-most byte

0x12345678
         ^-- right-most byte

In a big-endian memory layout that word would be stored as:

Address: N     N+1   N+2   N+3    
-------------------------------
Value:   0x12  0x34  0x56  0x78

And in a little-endian memory layout it would be stored as:

Address: N     N+1   N+2   N+3 
-------------------------------   
Value:   0x78  0x56  0x34  0x12