Lecture 4
 
- Main memory is one long single memory array of cells- The cells are bytes
- These are collapsed into words- Instructions are stored in words
- Words take 4 bytes of main memory
 
- Instructions are stored in words
 
- The cells are bytes
- Memory access- Data from memory to register- lw a, r(b)- Where 'b' is the base address
- 'r' is the relative address- Relative address MUST be a constant, cannot be a variable
 
- Relative address MUST be a constant, cannot be a variable
- 'a' is the absolute (actual) address of register
 
- Where 'b' is the base address
 
- Data to memory from register- sw a, r(b)- 'b' is base address
- 'r' is relative address- Relative address MUST be a constant, cannot be a variable
 
- Relative address MUST be a constant, cannot be a variable
- 'a' is absolute address from register STORE WORD to register from main memory
 
- 'b' is base address
 
 
- Compile Assignment and using main memory- Change c program into MIPS- g = h + A[8]
 
- g = h + A[8]
- MIPS program ( in Arial font)- lw $t0, 32($s3)- A[8]'s relative address is 32 ( 4*8 )
 
- A[8]'s relative address is 32 ( 4*8 )
- add $s1, $s2, $t0
 
- multiplying with mips- using previous example how do i get 4*i (without just knowing it)?- add $t1, $s4, $s4- find four times i
 
- find four times i
- add $t1, $t1, $t1- find absolute address
 
- find absolute address
- add $t1, $s3, $t1- t1 ß base + relative addresses- $s3 is the base address
 
- $s3 is the base address
 
- Lw $t0, 0($t1)- Load
 
- Load
- Add $s1, $s2, $t0- Add h + A[i]
 
- Add h + A[i]
 
 
- Beq reg1, reg2, label- Operands (register1, register2, label)
- If (r1=r2) then go to L1
 
 
- Operands (register1, register2, label)
- Bne reg1, reg2, label- Operands; (register, register2, label)
- If r1 != r2 then go to L2
 
- Operands; (register, register2, label)
 
---
 
 
 
 
If ( i == j ) then 
    F = g + h
    Else
    F = g – h
 
If ( i != j ) then go to else
    F = g + h;
    Go to exit;
Else
    F = g – h;
Exit
MIPS
bne $s3, $s4, Else
add $s0, $s1, $s2
j Exit #jump to exit
Else: sub $s0, $s1, $s2
Exit:
Loops
Example: 
Loop: g=g + A[i]
I=i+j;
If (i != h)  go to loop;
 
Loop 
- Get address of A[i]
- Load A[i]
- G ßg+A[i]
- I ßi+j
- If (i != h) go to loop
Steps 1-3 are the body, 4 is the modift, 5 is the stopping rule
 
MIPS
Loop: add $t1, $s3, $s3
Add $t1, $t1, $t1
Add $t1, $s5, $t1    #where $s5 is the base address of the array
Lw $t0, 0($t1)
Add $s1, $s1, $t0
Add $s3, $s3, $s4
Bne $s3, $s2, loop
Exit:
 
 
 
No comments:
Post a Comment