Escolar Documentos
Profissional Documentos
Cultura Documentos
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 1 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 2
Hi Lo
6. Addressing Modes TMU BadVaddr Trap &
(Coproc. 0) Status memory
Cause unit
Chapter Chapter Chapter EPC
10 11 12
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 3 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 4
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 5 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 6
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 7 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 8
add $t8,$s2,$s3 # put the sum b + c in $t8 Opcode Source Source Destination Shift Opcode
register 1 register 2 register amount extension
add $t9,$s5,$s6 # put the sum e + f in $t9
sub $s7,$t8,$t9 # set g to ($t8) − ($t9) 31
op
25
rs
20
rt
15
operand / offset
0
I 6 bits 5 bits 5 bits 16 bits
Decimal and hex constants
Opcode Source Destination Imm ediate operand
Decimal 25, 123456, −2873 or base or data or address offset
Hexadecimal 0x59, 0x12b4c6, 0xffff0000 op jump target address
31 25 0
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 9 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 10
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 11 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 12
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 13 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 14
name for J 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1
Solution
reg. $31 j=2
The first bit pattern has the hex representation: 0x2110003d (return
address) x x x x 0 0 0 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 15 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 16
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 17 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 18
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 19 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 20
Register
Reg spec Reg file Reg data Solution
Scan the list, holding the largest element identified thus far in $t0.
Constant offset Mem
Base
Reg base Reg Add addr Mem lw $t0,0($s1) # initialize maximum to A[0]
Reg file data Memory data
addi $t1,$zero,0 # initialize index i to 0
loop: add $t1,$t1,1 # increment index i by 1
Constant offset Mem
beq $t1,$s2,done # if all elements examined, quit
PC-relative
Add addr Mem
add $t2,$t1,$t1 # compute 2i in $t2
Memory data add $t2,$t2,$t2 # compute 4i in $t2
PC add $t2,$t2,$s1 # form address of A[i] in $t2
lw $t3,0($t2) # load value of A[i] into $t3
Pseudodirect PC
slt $t4,$t0,$t3 # maximum < A[i]?
Mem
addr Memory Mem beq $t4,$zero,loop # if not, repeat with no change
data addi $t0,$t3,0 # if so, A[i] is the new maximum
j loop # change completed; now repeat
Schematic representation of addressing modes in MiniMIPS. done: ... # continuation of the program
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 21 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 22
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 23 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 24
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 25 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 26
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 27 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 28
jal xyz sp c
b b
a sp a
Restore x = mem[sp]
sp = sp – 4
sp = sp + 4
jr $ra jr $ra mem[sp] = c
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 29 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 30
Map in
00400000 3. Parameters and Results
Text segment
Program
MiniMIPS 63 M words Stack allows us to pass/return an arbitrary number of values
10000000
Addressable Static data $sp z
with 16-bit 10008000 y
signed offset Data segment Local Frame for
..
1000ffff
Dynamic data variables . current
Saved procedure
registers
$gp 448 M words
Old ($fp)
$28 $sp
$29
$sp c $fp c
$30 b Frame for b Frame for
$fp current previous
Stack Stack segment a a
.. procedure .. procedure
. .
7ffffffc
80000000 $fp
Second half of address
space reserved for
memory-mapped I/O Before calling After calling
Overview of the memory address space in MiniMIPS. Use of the stack by a procedure.
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 31 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 32
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 33 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 34
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 35 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 36
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 37 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 38
Find the max element, swap it with the last item, move up the “last” pointer In $a0 max
Inputs to
x
Outputs from
y
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 39 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 40
op rs rt rd sh fn
op rs rt rd sh fn
31 25 20 15 10 5 0 31 25 20 15 10 5 0
R 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 x 0 R 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 x 0
ALU Source Source Unused Unused mult = 24
instruction register 1 register 2 div = 26 ALU Unused Source Destination Shift sll = 0
instruction register register amount srl = 2
The multiply (mult) and divide (div) instructions of MiniMIPS.
op rs rt rd sh fn op rs rt rd sh fn
31 25 20 15 10 5 0 31 25 20 15 10 5 0
R 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 x 0 R 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 x 0
ALU Unused Unused Destination Unused mfhi = 16
instruction register mflo = 18 ALU Amount Source Destination Unused sllv = 4
instruction register register register srlv = 6
MiniMIPS instructions for copying the contents of Hi and Lo registers into
general registers . The four logical shift instructions of MiniMIPS.
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 41 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 42
Instruction Usage op fn
Unsigned Arithmetic and Miscellaneous Instructions The 20 MiniMIPS Move from Hi mfhi rd 0 16
Instructions Copy Move from Lo mflo rd 0 18
Add unsigned addu rd,rs,rt 0 33
MiniMIPS instructions for unsigned arithmetic (no overflow exception): Subtract unsigned subu rd,rs,rt 0 35
addu $t0,$s0,$s1 # set $t0 to ($s0)+($s1) Multiply mult rs,rt 0 24
Arithmetic Multiply unsigned multu rs,rt 0 25
subu $t0,$s0,$s1 # set $t0 to ($s0)–($s1)
Divide div rs,rt 0 26
multu $s0,$s1 # set Hi,Lo to ($s0)×($s1) Divide unsigned divu rs,rt 0 27
divu $s0,$s1 # set Hi to ($s0)mod($s1) Add immediate unsigned addiu rs,rt,imm 9
# and Lo to ($s0)/($s1) Shift left logical sll rd,rt,sh 0 0
op rs rt rd sh fn
op
or base or data
Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 43 Jan. 2010 Computer Architecture – HEDSPI -HUT Slide 44