Top Banner
Fall 2006 Lillevik 333f06- l5 1 University of Portland School of Engineering EE 333 Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions
25

Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Jan 13, 2016

Download

Documents

Opal Holt
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 1University of Portland School of Engineering

EE 333

Computer OrganizationLecture 5

MIPS InstructionsLoops

Machine Instructions

Page 2: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 2University of Portland School of Engineering

EE 333

Last time

• MIPS assembly language

• Arithmetic and logic instructions

• Load and store instructions

Page 3: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 3University of Portland School of Engineering

EE 333

Write the program?betaalpharesult 6

Page 4: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 4University of Portland School of Engineering

EE 333

Lets run the program

Page 5: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 5University of Portland School of Engineering

EE 333

Instruction Classes

• Arithmetic and logic (some more)• Load: li, la, lbu, lw

• Store: sb, sw

• Comparison

• Branch and jump

• Data Movement

• Floating Point

Page 6: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 6University of Portland School of Engineering

EE 333

Arithmetic and Logic

Instruction Example MeaningAnd and $s1, $s2, $s3 $s1 = $s2 & $s3

And immediate andi $s1, $s2, 100 $s1 = $s2 & 100

Or or $s1, $s2, $s3 $s1 = $s2 | $s3

Or immediate ori $s1, $s2, 100 $s1 = $s2 | 100

Shift left logical sll $s1, $s2, 10 $s1 = $s2 << 10

Shift right logical srl $s1, $s2, 10 $s1 = $s2 >> 10

Only registers used for operands

Page 7: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 7University of Portland School of Engineering

EE 333

Instruction Classes

• Arithmetic and logic: add, sub, and, or

• Load: li, la, lbu, lw

• Store: sb, sw

• Comparison

• Branch and jump

• Data Movement

• Floating Point

Page 8: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 8University of Portland School of Engineering

EE 333

Branch and Jump

Instruction Example MeaningBranch on equal beq $s1, $s2, 100 If ($s1 = = $s2 ) go

to (PC +4 )+ 100

Branch on not equal bne $s1, $s2, 100 If ($s1 ! = $s2 ) go to (PC +4 )+ 100

Jump j loop Go to loop:

Jump and link jal subroutine $ra = PC + 4, go to subroutine

Jump Register jr $ra PC = $ra

Page 9: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 9University of Portland School of Engineering

EE 333

Loops in assembly

• Initialize loop counter

• Modify counter (decrement, increment)

• Check if counter = = end condition– True, leave loop– False, continue with loop

• Body of loop

• Continue with next pass in loop

Page 10: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 10University of Portland School of Engineering

EE 333

Flowchart of loopcount = 5

count --

count = = 0 ?

Body of loop

no

yes

Body could go ahead of test

Page 11: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 11University of Portland School of Engineering

EE 333

LoopsNOTE: you may place the

check after the body

How many times is “body” executed?

(4 or 5?

Page 12: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 12University of Portland School of Engineering

EE 333

Lets run the program

Page 13: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 13University of Portland School of Engineering

EE 333

Write the program?Write a loop that adds 4 to $t2, six times

Page 14: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 14University of Portland School of Engineering

EE 333

Machine Instructions

• Definition: numeric (hex) versions of instruction

• Memory: contains binary number or machine instruction, it’s what the hardware executes

• Formats– R, register– I, immediate– J, jump

NOTE: Result of assembly is a machine instruction

Page 15: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 15University of Portland School of Engineering

EE 333

Instruction Formats

Name FieldsSize 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits

R type op rs rt rd shamt funct

I type op rs rt address/immediate

J type op target address

All instructions are 32-bits long

32-bits

Page 16: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 16University of Portland School of Engineering

EE 333

R-format

• Operation (op) codeAll 0x00; exception mfc0 = 0x10,

• Funct determines specific instructionadd = 0x20, sub = 0x22, mult = 0x18, div = 0x1a

• Operands– rd = destination register– rs = first argument– rt = second argument

Shamt = shift amount

Page 17: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 17University of Portland School of Engineering

EE 333

R-format example

R type FieldsSize 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits

R type op rs rt rd shamt funct

00 0000 0 0011 0 0100 0 0010 0 0000 10 0000

add $2, $3, $4

add rd, rs, rt

0000 0000 0110 0100 0001 0000 0010 0000

0x 0064 1020

Page 18: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 18University of Portland School of Engineering

EE 333

Find machine instruction?

0x00d05022

R type FieldsSize 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits

R type op rs rt rd shamt funct

00 0000 0 0110 1 0000 0 1010 0 0000 10 0010

sub $10, $6, $16

sub rd, rs, rt

Page 19: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 19University of Portland School of Engineering

EE 333

I-format

• Op code exampleslw = 0x23, sw = 0x2b, beq = 0x04

• Operands– rs = first argument– rt = second argument

• Immediate = sign extended bits [15 – 0]

Page 20: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 20University of Portland School of Engineering

EE 333

I-format example

lw $2, 100($3)

lw rt, adr (rs)

1000 1100 0110 0010 0000 0000 0110 0100

0x 8c62 0064

Name FieldsSize 6 bits 5 bits 5 bits 16 bits

I type op rs rt address/immediate

10 0011 0 0011 0 0010 0000 0000 0110 0100

Page 21: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 21University of Portland School of Engineering

EE 333

Find machine instruction?

Name FieldsSize 6 bits 5 bits 5 bits 16 bits

I type op rs rt address/immediate

101011 0 1000 1 0100 0000 0000 0100 0000

sw $20, 64($8)

sw rt, adr (rs)

0xad14 0040

Page 22: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 22University of Portland School of Engineering

EE 333

Page 23: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 23University of Portland School of Engineering

EE 333

Write the program?Write a loop that adds 4 to $t2, six times

Page 24: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 24University of Portland School of Engineering

EE 333

Find machine instruction?

0x 00d0 5022

R type FieldsSize 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits

R type op rs rt rd shamt funct

00 0000 0 0110 1 0000 0 1010 0 0000 10 0010

sub $10, $6, $16

sub rd, rs, rt

Page 25: Fall 2006 1 EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.

Fall 2006

Lillevik 333f06-l5 25University of Portland School of Engineering

EE 333

Find machine instruction?

Name FieldsSize 6 bits 5 bits 5 bits 16 bits

I type op rs rt address/immediate

10 1011 0 1000 1 0100 0000 0000 0100 0000

sw $20, 64($8)

sw rt, adr (rs)

0x ad14 0040