CS计算机代考程序代写 mips Slide 1

Slide 1

Branches

1

Flow Chart Decisions
$t1 == $t2?
Start
Yes
No

Branch Instructions
beq $t5, $t3, my_label
Short for branch if equal
If $t5 == $t3 then go to my_label
Otherwise, continues to the next instruction

Branch Instructions
bne $t1, $t7, my_label
Short for branch if not equal
If $t1 != $t7 then go to my_label
Otherwise, continues to the next instruction

Branch Delay Slot
There is a delay of one cycle before a branch takes effect
This means the instruction immediately after a branch instructions is always executed

PLP/MIPS Pipeline

What should be in a branch delay slot?
2 Choices:
Nothing!
Use a nop instruction
Short for no operation
Takes up one cycle doing nothing
Put an instruction that:
Doesn’t effect the branch
Expected to run regardless of the branch outcome

Branch Delay Slot
Important: Jump instructions also have a branch delay after them
Same considerations apply
The delay slot wasn’t an issue in Project 1 because the jump was the last instruction

Example Situation
Assume $a0 already contains some value
If register $a0 contains a 1
Set $v0 to 2
If register $a0 contains any other value
Set $v0 to 4

Example Pseudo Code
if($a0 == 1) // if condition check
{
$v0 = 2; // if block
}
else // else condition
{
$v0 = 4; // else block
}

Solution Breakdown
If condition check

Else block

If block

Control Flow Visualization
Assume:
$a0 is 0
$t0 is 1
Expected Result
$v0 set to 4

Control Flow Visualization
Assume:
$a0 is 1
$t0 is 1
Expected Result
$v0 set to 2

Demo of Code

PLPTool Demo
Available in Video Lecture

15

/docProps/thumbnail.jpeg