Upload
opal-holt
View
215
Download
1
Embed Size (px)
Citation preview
Fall 2006
Lillevik 333f06-l5 1University of Portland School of Engineering
EE 333
Computer OrganizationLecture 5
MIPS InstructionsLoops
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
Fall 2006
Lillevik 333f06-l5 3University of Portland School of Engineering
EE 333
Write the program?betaalpharesult 6
Fall 2006
Lillevik 333f06-l5 4University of Portland School of Engineering
EE 333
Lets run the program
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
√
√
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
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
√
√
√
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
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
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
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?
Fall 2006
Lillevik 333f06-l5 12University of Portland School of Engineering
EE 333
Lets run the program
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
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
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
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
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
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
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]
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
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
Fall 2006
Lillevik 333f06-l5 22University of Portland School of Engineering
EE 333
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
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
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