Programming

8 September

Programming

Questions?

Instructions

We’ll be working with the MIPS instruction set architecture similar to other architectures developed since the 1980's

Design goals: maximize performance and minimize cost, reduce design time

MIPS arithmetic

C code: A = B + C 
MIPS code: add $s0, $s1, $s2 (associated with variables by compiler)

MIPS arithmetic

C code:

A = B + C + D; 
E = F - A;

MIPS code:

  add $t0, $s1, $s2 
  add $s0, $t0, $s3
  sub $s4, $s5, $s0

Registers versus Memory

Memory Organization

Instructions

    A[8] = h + A[8];

    lw $t0, 32($s3) 
    add $t0, $s2, $t0
    sw $t0, 32($s3)

So far we've learned

add $s1, $s2, $s3  # s1 = s2 + s3
sub $s1, $s2, $s3  # s1 = s2 – s3
lw $s1, 100($s2)   # s1 = Memory[s2+100]
sw $s1, 122($s2)   # Memory[s2+122] = s1

Machine Language

R-Format

op

rs

rt

rd

shamt

funct

6 bits

5 bits

5 bits

5 bits

5 bits

6 bits

000000

10001

10010

01000

00000

100000

Machine Language

Example: lw $t0, 32($s2)

I-format

op

rs

rt

16 bit number

35

18

9

32

Where's the compromise?

Stored Program Concept

Execution Example

ee1.png

Execution Example

ee2.png

Execution Example

ee3.png

Execution Example

ee4.png

Execution Example

ee5.png

Execution Example

ee6.png

Execution Example

ee7.png

Control

bne $t0, $t1, Label 
beq $t0, $t1, Label

Example: if (i==j) h = i + j;

bne $s0, $s1, Label
add $s3, $s0, $s1
Label:  ....

Control

j  label

Example:

if (i!=j)               
    h=i+j;
else
    h=i-j;
beq $s4, $s5, Lab1
add $s3, $s4, $s5
j Lab2
Lab1: sub $s3, $s4, $s5
Lab2: ...

So far

add $s1,$s2,$s3   # $s1 = $s2 + $s3
sub $s1,$s2,$s3   # $s1 = $s2 – $s3
lw $s1,100($s2)   # $s1 = Memory[$s2+100]
sw $s1,100($s2)   # Memory[$s2+100] = $s1
bne $s4,$s5,Label # Next instr. is at Label if $s4 != $s5
beq $s4,$s5,Label # Next instr. is at Label if $s4 = $s5
j Label           # Next instr. is at Label

R-Format

op

rs

rt

rd

shamt

funct

I-Format

op

rs

rt

16 bit address

J-Format

op

26 bit address

Control Flow

if  $s1 < $s2 then
    $t0 = 1
else
    $t0 = 0

Register Use Conventions

registeruse.png

Cultural Highlight

[WWW] Three Sides Exhibition

last edited 2005-09-08 14:31:01 by GaryBishop