Class 11.3 Set Instructions and more Branch Instructions.pptx

Download Report

Transcript Class 11.3 Set Instructions and more Branch Instructions.pptx

More Branch Instructions and Set
Instructions
• Branch on Less than Zero
• Branch on Greater than or equal to Zero
bltz
s,label
Branch if the two's comp. integer in register
bgez
s
is < 0
s
is >= 0
s,label
Branch if the two's comp. integer in register
A branch delay slot follows the instructions.
Set Instructions
• Set instructions set a register to 1 or 0 depending
on whether a condition is true or false.
• Set instructions do not jump but prepare the
registers for using by branch operations.
Set on Less Than
slt
d,s,t
Can the same patters
cause different result
in 2 instructions ?
sltu
d,s,t
#
#
#
$s and $t contain
two's comp. integers
#
#
#
#
if ( $s <
d <-- 1
else
d <-- 0
#
#
#
$s and $t contain
unsigned integers
# if ( $s <
#
d <-- 1
# else
#
d <-- 0
$t
$t
)
)
Set on Less Than Immediate
slti
d,s,imm
Which kind of
extension is done ?
sltiu
d,s,imm
#
#
#
#
#
#
$s and imm contain
two's comp. integers
if ( $s < imm )
d <-- 1
else d <-- 0
# $s and imm contain
# unsigned integers
#
# if ( $s < imm )
#
d <-- 1
# else d <-- 0
Counting Loop
 A common program loop is controlled by
an integer that counts up from an initial
value to an upper limit.
 Such a loop is called a counting loop.
 The integer is called a loop control
variable.
 Loops are implemented with the
conditional branch, jump, and conditional
set instructions.
Top or Bottom driven loops
 Usually you want a top-driven (while) loop
such as the one at right, where the test is
performed at the top before control enters
the loop body.
 Another case is Bottom driven loop do..while
 Be clear about the loop you want before you
program it, because assembly language
allows any sort of weird loop.
Counting Loop C
Here is the loop in C. It is intended to execute 10 times
starting at zero.
int j;
j = 0;
while ( j < 10 )
{
. . .
j++ ;
}
Counting Loop Assembly
Here is the loop in Assembly. It calculates the sum of
integers 0 through 9.
init:
test:
endLp:
ori
$8,$0,0
# count = 0
sltiu
beq
$9,$8,10
$9,$0,endLp
sll
$0,$0,0
# count < 10
# end loop
# if count >=10
# delay
addu
$10,$10,$8
# do stuff
# sum += count
addiu
j
sll
$8,$8,1
test
$0,$0,0
# count++ ;
sll
$0,$0,0
# branch target
# delay