Idea Transcript
CS 2630 Computer Organization Meeting 5: Stored programs Brandon Myers University of Iowa
Where we are going Compiler
Instruction set architecture (e.g., MIPS) Memory system
Processor Datapath & Control Digital logic
translating source code (C or Java) Programs to assembly language And linking your code to Library code How the software talks To the hardware I/O system How a processor runs MIPS Programs! How switches (1 or 0) can be used to build Interesting functions: from integer arithmetic to programmable computers
Where we are going
Instruction memory
Learn what gets stored in here
Execution engine
Data memory
Peer instruction • MIPS program reading
Storing an instruction as bits • each MIPS instructions is 32 bits, stored in “instruction memory” contents
meaning
address 0000
8e
13
00
00
lw
$s3, 0($s0)
0004
8e
14
00
04
lw
$s4, 4($s0)
0008
02
74
90
20
add
$s2, $s3, $s4
000C
ae
12
00
08
sw
$s2, 8($s0)
0010
22
10
00
04
addi $s0, $s0, 4
0014
22
31
ff
ff
addi $s1, $s1, -1
0018
1e
20
ff
f9
bgtz $s1, loop
Storing an instruction as bits each MIPS instructions is 32 bits, stored in “instruction memory” contents
meaning
address 0000
8e
13
00
00
lw
$s3, 0($s0)
0004
8e
14
00
04
lw
$s4, 4($s0)
0008
02
74
90
20
add
$s2, $s3, $s4
000C
ae
12
00
08
sw
$s2, 8($s0)
0010
22
10
00
04
addi $s0, $s0, 4
0014
22
31
ff
ff
addi $s1, $s1, -1
0018
1e
20
ff
f9
bgtz $s1, loop
R-type
Example:
0x00
8
9
13
0
0x20
000000 01000 01001 01101 00000 100000 0x01096820 MIPS green sheet, P&H
I-type
Example:
0x09
10
14
-1
001001 01010 01110 11111 11111 111111 0x254EFFFF MIPS green sheet, P&H
Peer instruction Give the 32-bit representation of this instruction
a) b) c) d) e)
0x00231025 0x014B4825 0x00430825 0x00611025 0x01695025
More instructions
Instruction execution
Instruction execution PC 00x0000 contents
meaning
address 0000
8e
13
00
00
loop: lw $s3,0($s0)
0004
8e
14
00
04
lw
$s4, 4($s0)
0008
02
74
90
20
add
$s2, $s3, $s4
000C
ae
12
00
08
sw
$s2, 8($s0)
0010
22
10
00
04
addi $s0, $s0, 4
0014
22
31
ff
ff
addi $s1, $s1, -1
0018
1e
20
ff
f9
bgtz $s1, loop
Instruction execution PC 0x0004 contents
meaning
address 0000
8e
13
00
00
loop: lw $s3,0($s0)
0004
8e
14
00
04
lw
$s4, 4($s0)
0008
02
74
90
20
add
$s2, $s3, $s4
000C
ae
12
00
08
sw
$s2, 8($s0)
0010
22
10
00
04
addi $s0, $s0, 4
0014
22
31
ff
ff
addi $s1, $s1, -1
0018
1e
20
ff
f9
bgtz $s1, loop
Instruction execution PC 0x0008 contents
meaning
address 0000
8e
13
00
00
loop: lw $s3,0($s0)
0004
8e
14
00
04
lw
$s4, 4($s0)
0008
02
74
90
20
add
$s2, $s3, $s4
000C
ae
12
00
08
sw
$s2, 8($s0)
0010
22
10
00
04
addi $s0, $s0, 4
0014
22
31
ff
ff
addi $s1, $s1, -1
0018
1e
20
ff
f9
bgtz $s1, loop
Instruction execution PC 0x0018 contents
meaning
address 0000
8e
13
00
00
loop: lw $s3,0($s0)
0004
8e
14
00
04
lw
$s4, 4($s0)
0008
02
74
90
20
add
$s2, $s3, $s4
000C
ae
12
00
08
sw
$s2, 8($s0)
0010
22
10
00
04
addi $s0, $s0, 4
0014
22
31
ff
ff
addi $s1, $s1, -1
0018
1e
20
ff
f9
bgtz $s1, loop
Instruction execution
branches use “relative addressing”
PC 0x0018 contents
meaning
address 0000
8e
13
00
00
loop: lw $s3,0($s0)
0004
8e
14
00
04
lw
$s4, 4($s0)
0008
02
74
90
20
add
$s2, $s3, $s4
000C
ae
12
00
08
sw
$s2, 8($s0)
0010
22
10
00
04
addi $s0, $s0, 4
0014
22
31
ff
ff
addi $s1, $s1, -1
0018
1e
20
ff
f9
bgtz $s1, loop
0xfff9 = -7 0x0018 + 4 + (-7 * 4) = 0x0000
Jumps: absolute addressing
Peer instruction
What is the maximum distance you can jump using a single j? a) b) c) d) e) f)
25 instructions 26 instructions 224 instructions 225 instructions 226 instructions 230 instructions
Administrivia • reminder: HW2 due Thursday 11:59pm • 1. download/run MARS, • 2. watch MARS tutorials lesson 1 and 2 (under ICON > modules) • 3. write the two MIPS programs
• Project 1 out later this week (MIPS programs/assembly) • Debug Your Brain tonight (at the new time 5-6pm CT)