Download Encoding for the GPRs - Computer Architecture - Lecture Slides and more Slides Computer Architecture and Organization in PDF only on Docsity!
SRC: instruction formats
Op-code ra rb
rc c
Type D
Op-code
Type A unused
Op-code ra
Type B c
Op-code ra rb
Type C c
Encoding for the GPRs
to be used in place of ra, rb, or rc
Register Code Register Code Register Code Register Code
R0 00000 R8 01000 R16 10000 R24 11000
R1 00001 R9 01001 R17 10001 R25 11001
R2 00010 R10 01010 R18 10010 R26 11010
R3 00011 R11 01011 R19 10011 R27 11011
R4 00100 R12 01100 R20 10100 R28 11100
R5 00101 R13 01101 R21 10101 R29 11101
R6 00110 R14 01110 R22 10110 R30 11110
R7 00111 R15 01111 R23 10111 R31 11111
Notes: simple 5-bit encoding as shown above; ra, rb, rc are names of fields,
used as “place-holders”, and can represent any one of these 32 registers.
Except : rb =0 does not mean R0; explained later
three instructions; all three use relative addressing mode
ldr (op-code = 2 ) load register from memory using relative address
ldr R3, 56 R[3] M[PC+56]
lar (op-code = 6 ) load register with relative address
lar R3, 56 R[3] PC+
str (op-code = 4) store register to memory using relative address
str R8, 34 M[PC+34] R[8]
the effective address is computed at run-time by adding a
constant to the PC
makes the instructions relocatable
Type B
Op-code ra
c
Note: R8 is register name and R[8] means contents of register R
Type C
Op-code ra rb
c
three load/store instructions, plus three ALU instructions
ld (op-code = 1 ) load register from memory
ld R3, 56 R[3] M[56] (rb field = 0)
ld R3, 56(R5) R[3] M[56+R[5]] (rb field ≠ 0)
la (op-code = 5 ) load register with displacement address
la R3, 56 R[3] 56
la R3, 56(R5) R[3] 56+R[5]
st (op-code = 3 ) store register to memory
st R8, 34 M[34] R[8]
st R8, 34(R6) M[34+R[6]] R[8]
direct addressing
mode
Indexed
addressing
mode
Immediate addressing mode
Indexed
addressing
mode
direct addressing
mode
Type C
(modified form)
Op-code ra rb
unused
….(additional) four shift instructions
shr (op-code = 26) shift right by using value in (5-bit) c3 field
shr R3, R4, 7 shift R4 right 7 times in to R
shra (op-code = 27) Arithmetic shift right by using value in c3 field
shra R3, R4, 7 Ashift R4 right 7 times in to R
shl (op-code = 28) shift left by using value in (5-bit) c3 field
shl R8, R5, 6 shift R5 left 6 times in to R
shc (op-code = 29) shift left? circular by using value in c3 field
shc R3, R4, 3 shift R4 circular 3 times in to R
Note: If count field contains 0, then these instructions will use the modified Type D format
count
All use immediate addressing mode
Type D
four ALU instructions, plus others explained on following slides
add (op-code = 12) 2’s C register addition
add R3, R5, R6 R[3] R[5] + R[6]
sub (op-code = 14) 2’s C register subtraction
sub R3, R5, R6 R[3] R[5] - R[6]
and (op-code = 20) logical AND operation between registers
and R8, R3, R4 R[8] R[3] & R[4]
or (op-code = 22) logical OR operation between registers
or R8, R3, R4 R[8] R[3] ~ R[4]
register addressing mode
Op-code ra rb
rc
unused
Type D
(modified forms
for branch instr )
… plus two branch instructions
br (op-code = 8) branch to address in rb depending on
condition in rc (five possible conditions)
brzr R3, R4 branch to address in R3 (if R4 == 0)
brnz R3, R4 branch to address in R3 (if R4 ≠ 0)
brpl R3, R4 branch to address in R3 (if R4 ≥ 0)
brmi R3, R4 branch to address in R3 (if R4 < 0)
br R3 branch to address in R3 (unconditional)
Op-code unused rb
rc
unused
cond
Type D
(modified forms
for branch instr )
brl (op-code = 9) branch to address in rb depending on condition in rc.
Additionally, copy the PC in to ra before branching
Op-code ra rb
rc
unused
cond
Branch and link
examples
Function
brlzr R1,R3, R4 R[1] PC, then branch to address in R3 (if R4 == 0)
brlnz R1,R3, R4 R[1] PC, then branch to address in R3 (if R4 ≠ 0)
brlpl R1,R3, R4 R[1] PC, then branch to address in R3 (if R4≥ 0)
brlmi R1,R3, R4 R[1] PC, then branch to address in R3 (if R4 < 0)
brl R1,R3 R[1] PC, then ALWAYS branch to address in R
brlnv R1 R[1] PC, NEVER BRANCH
Mnemonic
lang.
Example instr. Meaning op ra rb rc c
Branch
Cond’n.
brlnv brlnv r
R[6]
PC
9 6 — — 000 never
br br r
PC
R[4]
8 — 4 — 001 always
brl brl r6,r
R[6]
PC;
PC
R[4]
9 6 4 — 001 always
brzr brzr r5,r1 if (R[1]=0)
PC
R[5]
8 — 5 1 010 zero
brlzr brlzr r7,r5,r
R[7]
PC;
9 7 5 1 010 zero
brnz brnz r1, r if (R[0]
0) PC
R[1]
8 — 1 0 011 nonzero
brlnz brlnz r2,r1,r
R[2]
PC;
if (R[0]
0) PC
R[1]
9 2 1 0 011 nonzero
brpl brpl r3, r
if (R[2]>= 0) PC
R[3]
8 — 3 2 100 plus
brlpl brlpl r4,r3,r
R[4]
PC;
if (R[2]>= 0) PC
R[3]
9 4 3 2 plus
brmi brmi r0, r
if (R[1]<0) PC
R[0]
8 — 0 1 101 minus
brlmi brlmi r3,r0,r
R[3]
PC;
if (r1<0) PC
R[0]
9 3 0 1 minus
Table 2.6,