Lec6MIPS_after

Lec6MIPS_after - Program Memory MIPS memory operations...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Program Memory MIPS memory operations Getting Variable Addresses Advanced structures Registers vs Memory Registers are memory Everything residing in a register has a real home Variables live in memory and are brought into registers When that register is needed for something else, the item fast, temporary in memory (with an associated address) for computations is stored back to memory. Memory Setup in C/Java int X; What does this do? What does the memory look like? X is located here. An int is 4 bytes, so it takes 4 locations &X &X + 4 &X means address of X Operation # comment lw $2, 32($3) # $2 <- M[32 +$3] sw $2, 16($3) # M[16 +$3] <- $2 lb $2, 0($3) # $2 <- M[0 +$3] sb $2, 3($3) # M[3 +$3] <- $2 Load/Store Instructions Displacement addressing mode Register indirect is Displacement with 0 offset lw = load word (4 bytes), lb = load byte (1 byte) Memory Addressing Modes Mode Example Meaning Use Displacement Lw R4, 100(R1) $4 <- M[$1 + 100] Arrays w/constant offset Register Indirect Lw R4, (R1) $4 <- M[$1] You have pointer Indexed Lw R4, (R1+R2) $4 <- M[$1 + $2] $1 has base,$2 has offset Direct or absolute Lw R4, (1001) $4 <- M[1001] Globals, static data? Memory indirect Lw R4, @(R1) $4 <- M[M[$1]] Double-pointer Autoincrement Lw R1, (R2) + $4 <- M[$2], $2 = $2 + d Stepping through array in loop Autodecrement Lw R1, (R2) - $4 <- M[$2], $2 = $2 - d Stepping through array in loop Scaled Lw R4, 100(R2)[R3] $4 <- M[100+$2+ ($3*d)] Indexing arrays of large elements MIPS supports ONLY Displacement mode Register Indirect and Direct are supported implicitly by Displacement Address depends on variable type Local variables on the stack Global variables declared and allocated in data segment Heap variables (malloc or new) Declaring, Allocating & Initializing Global Variables C: int GlobalA = 3; int main(int argc, char *argv) { } Java: public class MyClass{ public static int GlobalA = 3; }; MIPS: .data GlobalA: .word 0x03; .text main: Declaring & Initializing Local Variables in HLL C: int main(int argc, char *argv) { int LocalA = 5; } Java: public class MyClass { public static void main(String argv) { int LocalA = 5; } }; MIPS: add $sp, $sp, -(24 + x + 4) # where x is space for preserved regs addi $t0, $0, 5 sw $t0, 0 ($sp) Declaring & Initializing Heap Variables in HLL C: int main(int argc, char *argv) { int *LocalA = (int *)malloc(4); *LocalA = 5; } add $sp, $sp, -(24 + x + 4) # where x is space for preserved regs addi $a0, $0, 4 jal malloc sw $v0, 0($sp) addi $t0, $0, 5 sw $t0, 0($v0) Java: int main(int argc, char *argv) { int LocalA = new int[1] LocalA[0] = 5; } How do I get &A?...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 30 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 35

Lec6MIPS_after - Program Memory MIPS memory operations...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online