csl.skku.edu

Download Report

Transcript csl.skku.edu

컴퓨터구조 – 중간시험 (답안지)
1.
MIPS ISA는 필요한 소수의 instruction만을 제공하기 때문에 MIPS assembly language에서는
pseudoinstruction을 제공하여 보다 다양한 instruction을 가지고 프로그래밍을 하게 해준다.
다음에 주어지는 pseudoinstruction들을 MIPS ISA가 제공하는 instruction으로 바꾸어라.
단, 다음의 MIPS instruction과 register와 constant convention을 참조하시오. [총 20점]
$zero : constant value 0 (hardwired)
$at : assembler temporary register
r1, r2, r3, $t0, $t1, $t2, $t3, $t4, $t5 : MIPS integer registers
Imm16, small : 16-bit constant
big : 32-bit constant (단, big_hi는 big[31:16]으로 16-bit constant, big_lo는 big[15:0]으로 16-bit
constant를 의미한다고 가정하시오)
Label, L : branch target
add
addi
beq
bne
slt
lui
ori
lw
r1, r2, r3
r1, r2, Imm16
r1, r2, Label
r1, r2, Label
r1, r2, r3
r1, Imm16
r1, r2, Imm16
r1, Imm16(r2)
Pseudoinstruction
// r1 = r2 + r3
// r1 = r2 + Imm16
// if (r1 = r2) go to Label
// if (r1 != r2) go to Label
// if (r2 < r3) r1 = 1 else r1 = 0
// r1[31:16] = Imm16; r1[15:0] = 0
// r1 = r2 bit-wise-or Imm16
// r1 = Memory[r2+Imm16]
meaning
부분점수 (사소한 실수면 -1)
MIS ISA translation
[각 4점]
(a) clear $t0
// $t0 = 0
=> add $t0, $zero ,
혹은 addi
$zero
(b) beq $t1, small, L
// if ($t1 = small) go to L
=> addi
beq
$at,
$t1,
(c) addi $t0, $t2, big
// $t0 = $t2 + big
=>
$at,
big-hi
$at, $at ,
big-lo
$t0, $t2, $at
(d) bge $t5, $t3, L
// if ($t5 >= $t3) go to L
=>
(e) lw $t5, big($t2)
// $t5 = Memory[$t2+big]
=>
lui
ori
add
slt
beq
lui
ori
lw
$at,
$at,
$zero
0
$zero , small
$at
, L
$t5 , $t3
$zero , L
$at, big-hi
$at, $at ,
$t5, 0($at)
big-lo
2. 다음의 IEEE 754 floating point standard에 따른 bit representaion을 참조하여 주어진 값을
작은 수 부터 큰 수 순으로 나열하시오. [10점] 부분점수 (0, 2, 10)
normalized:
exponent != 0 and exponet != 1인경우, 아래와 같은 값
(–1)sign x (1 + significand) x 2exponent – bias (single precision FP bias = 127)
denormalized: exponent = 0인 경우, 아래와 같은 값
(–1)sign x (significand) x 21 – bias (single precision FP bias = 127)
special:
exponent = 11111111, significand = 0인 경우, sign에따라 infinity
31
30
sign
23 22
exponent
0
significand
(a)
1 11100111 01100000000000000000000
(b)
1 11100111 01000000000000000000000
(c)
1 00000000 01000000000000000000000
(d)
0 00000000 10000000000000000000000
(e)
0 00100110 11111111111111111111111
(f)
0 00100111 00000000000000000000000
(g)
0 11111111 00000000000000000000000
a
b
음수
c
d
e
양수
최소한 위의 그룹핑이 되면 2점
f
g
+무한대
step name
R-type
memory
reference
instruction
fetch
branch (beq) jump
IR <= Memory[PC]
PC <= PC + 4
instr decode/
register fetch
A <= Reg[IR[25:21]], B <= Reg[IR[20:16]]
ALUOut <= PC + (sign-extend(IR[15:0]) <<2)
execution/addr
calculation
ALUOut <= A op B
ALUOut <= A+
signextend(IR[15:0]
memory access
Reg[IR[15:11]]
<= ALUOut
Load:
MDR<=Memory[ALUOut]
If (A==B)
PC <= ALUOut
PC<={PC[31:28],
(IR[25:0]),2’b00
X
X
X
X
Store:
Memory[ALUOut]<=B
memory read
completion
X
Load:
Reg[IR[20:16]] <= MDR
3. 위 표는 MIPS 명령어의 Multicycle 실행을 위한 5-단계를 RTL 수준으로 설명하고 있다. 뒷 장
의 datapath 를 참조하여 다음 질문에 답하시오. [총 20점]
(a) 위 표에 빠진 4 부분을 표에 채우시오. R type 명령어의 destination register 는 IR[15:11] 이며 load 명령어의
destination register 는 IR[20:16] 임. memory reference 명령어의 memory access step 은 load 와 store 로 나누어 설
명. [10점] 부분점수 부여 (0, 2, 5, 7, 10)
(b) 뒤에 나오는 datapath를 사용할 때, Step 2(decode) 단계의 ALUOut <= PC + (sign-extend(IR[15:0]) <<2) 작업을
Step 3으로 미루면 어떤 문제가 발생하는가? [5점] 부분점수 고려 (2, 5)
R-type, memory-ref, branch (단, jump 제외) 명령어가 모두 ALU를 사용하는 operation을 3단계에서 하고 있으므로
multicycle 구조에서 2단계에서 수행하던 계산을 옮겨오면 ALU를 두번에 걸쳐 사용하므로 그 결과를 중간에 저장할
internal register가 없으며 3단계를 1 cycle만에 수행할 수 없다. (1 cycle이 길어진다는 취지로 쓴 경우 부분 점수 2
점)
실제 2단계에서 하는 계산이 branch에만 필요하므로 branch의 3단계에서 수행하도록 하여도 마찬가지로
ALU의 A==B (subtract)의 계산과 중복되어 ALU를 사용하므로 앞의 이유와 마찬가지로 3단계를 1 cycle만에 수행할
수 없다.
(c) Step 2의 주소계산, ALUOut <= PC + (sign-extend(IR[15:0]) <<2) 에서는 offset 부분을 shift(<<2)하여 4를 곱한
값으로 만드나 Step 3의 memory reference 에서는 주소값을 shift 없이 그대로 사용하는 이유는 무엇인가? [5점] 부분
점수 고려 (2, 5) – (하나만 제대로 설명했을 경우 2점)
Step 2의 주소 계산은 branch target 주소를 계산하는 것이므로 MIPS명령어가 모두 4 byte 크기를 가지고 명령어 4
byte 주소에 align되어 있으므로 branch target 주소는 항상 4의 배수인점을 고려하여 PC-relative addressing mode
가 immediate을 2bit shift하여 사용하도록 되어 있다.
Step3의 주소 계산은 memory reference (lw, sw)를 위한 데이터 주소 계산이며 데이터는 1 byte단위의 주소별로 접
근이 가능한 점을 고려하여 base-addressing mode에서 shift없이 주소를 계산하도록 되어 있다.
PC
0
M
u
x
1
W rite
da ta
M e m D a ta
M e m ory
Addre ss
Op
[5 – 0 ]
Control
Outputs
M e m ory
da ta
re giste r
Instruction
[1 5 – 0 ]
Instruction
re giste r
Instruction
[1 5 – 0 ]
Instruction
[2 0 – 1 6 ]
Instruction
[2 5 – 2 1 ]
Instruction
[3 1 – 2 6 ]
0
M
u
x
1
R ead
re giste r 2
R ead
re giste r 1
R e gD st
R e gW rite
ALU S rcA
ALU S rcB
ALU O p
P C S ource
32
Instruction [5 – 0 ]
S ign
e xte nd
W rite
da ta
re giste r
R ead
da ta 2
R ead
da ta 1
(3) W rite R e giste rs
16
0
M
Instruction u
x
[1 5 – 11 ]
1
(2)
(1)
Instruction [2 5 -0 ]
IR W rite
M e m toR e g
M e m W rite
M emR ead
IorD
P C W rite
P C W rite C ond
S hift
le ft 2
B
A
4
3
28
ALU
control
ALU ALU
re sult
Z e ro
P C [3 1 – 2 8 ]
S hift
le ft 2
(5)
(4)
1 M
u
2 x
0
0
M
u
x
1
26
ALU O ut
Jum p
a ddre ss
[3 1 – 0 ]
M
1 u
x
2
0
(6)
4. 앞 장의 datapath 그림을 참조하여 다음 명령어가 실행될 때 그림에 표시된 datapath에
정의되는 값을 채우시오. 각 register는 자기 번호를 초기 값으로 갖고 있다고 가정, 즉 $17의
초기 값은 17임. (의미 없는 값은 X로 표시, 모르는 메모리 값은 M으로 표시) [총 20점]
예) add $8, $17, $18 (opcode=0, rs=17, rt=18, rd=8, shamt=0, funct=32)
1
2
3
4
5
6
instruction fetch
x
x
x
0
4
4
decode/ r-fetch
17
18
x
x
x
x
exe/addr calc
x
x
x
17
18
x
mem access
x
x
8
x
x
x
mem finish
x
x
x
x
x
x
a) beq $7, $8, 503 (opcode=4, rs=7, rt=8, immediate=503) [10점] - 숫자로 써야 할곳만 제대로
썼는지 검사, X는 뭐라고 썼든지 내버려둘것 – 부분점수 (0, 2, 5, 7 10)
1
2
3
4
5
6
instruction fetch
x
x
x
100
4
104
decode/ r-fetch
7
8
x
104
2012
x
exe/addr calc
x
x
x
7
8
2012,
혹은 x
mem access
x
x
x
x
x
x
mem finish
x
x
x
x
x
x
b) lw $3, 13($2) (opcode=35, rs=2, rt=3, immediate=13) [10점] – 숫자로 써야 할곳만 제대로 썼
는지 검사, X는 뭐라고 썼든지 내버려둘것 – 부분점수 (0, 2, 5, 7 10)
1
2
3
4
5
6
instruction fetch
x
x
x
10
4
14
decode/ r-fetch
2
x
x
x
x
x
exe/addr calc
x
x
x
2
13
x
mem access
x
x
x
x
x
x
mem finish
x
x
3
x
x
x
Instructionfetch
MemRead
ALUSrcA= 0
IorD = 0
IRWrite
ALUSrcB= 01
ALUOp= 00
PCWrite
PCSource = 00
0
Start
Memoryaddress
computation
2
ALUSrcA= 1
ALUSrcB=
ALUOp = 00
6
3
Memory
access
5
MemRead
IorD = 1
ALUSrcA= 0
ALUSrcB=
ALUOp=
11
00
Jump
completion
8
ALUSrcA= 1
ALUSrcB= 00
10
ALUOp=
Memory
access
1
Branch
completion
Execution
10
Instructiondecode/
register fetch
9
ALUSrcA= 1
ALUSrcB= 00
ALUOp =
PCWriteCond
PCSource =
PCWrite
01 PCSource =
10
01
R-type completion
7
MemWrite
IorD = 1
RegDst =
RegWrite
MemtoReg = 0
1
Memory read
completon step
4
RegDst =
RegWrite
MemtoReg=
0
1
5. 위 그림은 MIPS control logic 을 finite state machine으로 표시한 것이다. 앞의 datapath 그림을 참조하
여 각 state에서 보내는 control signal 값 중 검은 박스(
)로 표시된 부분의 값을 정하여 위 그림에 표시
하시오. (총 10개) [30점] 하나당 3점부여
ALUOp 의 의미는 (00: add, 01: sub, 10: funct field decides) 으로 정한다.