Name: Box: Date:
HW9 solution
-
You are writing a MIPS assembly program. Your program has a
beq
instructions at line0x0100 0400
. You wish thisbeq
to branch to location0x0200 0000
.-
(3 points) How close can the
beq
get to the goal address? Express your answer as the address nearest to the target address as possible.The
beq
is at0x0100 0400
, so PC+4 is at0x0100 0404
. The biggest positive number that can be put in the immediate value is0x7fff
. So
0x0100 0404 + SE(0x7fff << 2) = 0x0102 0400 -
(3 points) What is a possible method to allow long-range conditional branches?
Since branches can only go as far as the 16-bit immediate allows (\(-2^{15} -- 2^{15}-1\) ), longer ranges can be implemented by branching to a
j
instruction. For even longer ranges, the target can be loaded into a register andjr
can be used to jump.
-
-
You are writing a program for a processor with 8-bit instructions. The branch instructions for this processor only allow 3-bit branch immediate.
-
(3 points) Assuming the immediate is sign extended, what is the branch range of the processor?
Since there are 3 bits, \(2^3 = 8\) possible locations, for a range of -4 to 3
-
(3 points) What is the problem with such a branch range?
It is very limited and makes writing loops and conditions very hard.
-
-
Compute the correct hex value for the branch targets below.
Address Instruction Hex representation 0x00400028
j test
0x08QQQQQQ
0x0040002c
loop: lw $t1, 0($11)
0x8d690000
0x00400030
addi $t3, $t3, -4
0x216bfffc
0x00400034
test: bne $t1, $0, loop
0x1520RRRR
-
(3 points) What is the hex value for
QQQQQQ
that represents the jump target? Show your work.Given the target
0x0040 0034
and PC+4 at0x0040 002c
:
0x00400034 = top4(0x0040002c) : imm << 2
Solving results in:imm = 0x001000d
-
(3 points) What is the hex value for
RRRR
that represents the branch not equal target? Show your work.Given a target of
0x0040 002c
and a PC+4 of0x0040 0038
:
0x0040002c = 0x00400038 + SE(imm << 2)
Solving results in:
imm = 0xfffd
-