DylsexicChciken Posted February 25, 2015 Posted February 25, 2015 (edited) 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 February 25, 2015 by DylsexicChciken
Sensei Posted February 26, 2015 Posted February 26, 2015 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now