Jump to content

MIPS assembly language

Featured Replies

Let $s6 be the base address of an array A and $t0 contains some value. When you add:

 

add $t0, $s6, $t0

 

Does register $s6 refer to a value or an address? More importantly, what does $t0 contain? Does $t0 contain a value or an address? How does the computer know whether the register refers to values or addresses?

If it is a value, then how is it possible to do this afterward:

 

lw $s0, 0($t0)

 

How can a register have a set of offset addresses? Does the address of A carry over to $t0? If so where are they stored, because obviously $t0 is used to store the data. I thought offsets only applied to arrays. So does $s6 and $t0 both refer to an address and a value?

 

Is $s6 by default equivalent to 0($s6)?

Edited by DylsexicChciken

Let $s6 be the base address of an array A and $t0 contains some value. When you add:

 

add $t0, $s6, $t0

 

Does register $s6 refer to a value or an address? More importantly, what does $t0 contain? Does $t0 contain a value or an address? How does the computer know whether the register refers to values or addresses?

You're just calculating new address.

 

In C/C++ it would be:

char *address;

int offset;

char *new_address = address + offset;

 

Actually it's meaningless whether it's address or integer. Because result will be the same. Just adding two together.

 

On many CPUs if you want to increment/change some memory location, you need to load that memory location to register, increment/change register, and store register in the same place.

 

If it is a value, then how is it possible to do this afterward:

 

lw $s0, 0($t0)

You calculated register $t0, and now want to read word from memory address at $t0+0, and store it in register $s0

 

Equivalent to C/C++:

unsigned long data = *( (unsigned long *) new_address ); // if word = 32 bits.

 

If it would be f.e.

 

lw $s0, 100($t0)

 

Equivalent to C/C++:

unsigned long data = *( (unsigned long *) ( &new_address[ 100 ] ) ); // if word = 32 bits.

 

How can a register have a set of offset addresses?

In this case offset 0 is hard-coded in instruction.

See Encoding of LW instruction in link below.

 

If so where are they stored, because obviously $t0 is used to store the data.

Data from memory location at $t0+0 will be stored in $s0

 

I thought offsets only applied to arrays.

Offsets are essential for structures and class object members.

 

Arrays have indexes. Offset in array is equivalent to sizeof( struct ) * index

Full multiply of size of single element of array.

 

f.e.

struct Data

{

char Name[ 16 ];

long Age;

long Sex;

};

 

will have Name at offset 0

Age at offset 16

Sex at offset 16+4=20

and sizeof( Data ) = 16+4+4=24

 

So does $s6 and $t0 both refer to an address and a value?

 

Is $s6 by default equivalent to 0($s6)?

I don't think so

$s6 is most probably operation on register

while

0($s6) is read/write of memory location specified by register.

 

See this

http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html

You have description of operation in 2nd row of table of each instruction.

It has even Encoding supplied, so you can see which registers/data/offsets are in which bits of instruction.

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.