Simulated MIPS Machine Memory Layout ------------------------------------ The space that we allocate for you looks like this: +---------------+ $a2---->| | | Stack (grows | | down) | | | | | | | | | | | | | | | | | When we allocate this space, | | we call it "static" | | | | | | | | | | | | | Code, loaded | | in, one instr | | per word | $a1---->| |<-----$a3 +---------------+ +---------------+ | | $a0---->| Register | +---------------+ $a0 = pointer to first word of the register space $a1 = pointer to first word of your code/static/stack space $a2 = pointer to last word of your code/static/stack space $a3 = pointer to first word of code (actually the same as $a1) $a0 - $a3 are all real pointers, i.e., they do in fact point to SPIM memory locations. Conceptually, the registers are the only area of memory that is separate from the rest. References to Code or Stack Space --------------------------------- All references to either code or stack space should be done relative to the $a1 pointer. For example, say you have a load word instruction running on your virtual machine: lw $t0, offset($s0) What you would need to do is: (Recall that $t0 is $8 and $s0 is $16) 1) get the value of virtual register $s0 (by accessing SPIM memory $a0 + 16*4). 2) add the offset to calculate the virtual memory location. 3) convert virtual memory address to SPIM memory address by adding in $a1. 4) get the value at the SPIM memory location calculated in 3). 5) put it in virtual register $t0 (SPIM memory $a0 + 8*4). Stores, branches, etc. work similarly. Just remember that whenever you access memory locations, whether to retrieve instructions or to store data, etc., you'll need to add in an extra $a1 offset in order to translate to the SPIM memory. In other words: Virtual Machine's Address 0 = SPIM memory at the contents of $a1 Virtual Machine's memory extends from byte 0 up to byte 2047 (for a total of 2048 bytes), which is the same thing (in SPIM) as saying that the memory locations go from $a1 to $a2. Note that $a2 = $a1 + 2044 initially as $a2 points to the last word (not byte).