99logic_lab9

Download Report

Transcript 99logic_lab9

LAB 9
Simple ALU
擲骰子電路實作
NCKU EE CAD
9-1 Simple ALU
設計一個具有下表運算功能的ALU 電路:
opcode
3’d0
3’d1
3’d2
3’d3
3’d4
3’d5
3’d6
3’d7
執行功能
NOP,不需執行運算,result=4'd0,
overflow=1'd0
AND,in1 & in2,overflow=1’d0
OR,in1 | in2,overflow=1’d0
XOR,in1^in2,overflow=1’d0
ADD,in1+in2
SUB,in1-in2
邏輯左移,overflow=1’d0
邏輯右移,overflow=1’d0
ASIC Lab 2
NCKU EE CAD
9-1 Simple ALU
附註:
此ALU 的輸入與輸出皆視為有號數(使用2的補數)。
此題溢位(overflow)指的是超出result 所能表示範圍,例如:
opcode = 3’d4,
in1 = 4’b0001,in2 = 4’b0111, result = 4’b1000
結果應該為1 + 7 = 8,但是因為有號數的關係,已超出可表示範圍,所
以結果變為(‐8),因此overflow = 1’b1。
指令舉例:
opcode=3’d1,
in1=4’b0111,in2=4’b0010,in1&in2,result=4’b0010, overflow=1’d0
ASIC Lab 3
NCKU EE CAD
9-1 Simple ALU
opcode=3’d2,
in1=4’b0111,in2=4’b0010,in1|in2,result=4’b0111, overflow=1’d0
opcode=3’d3,
in1=4’b0111,in2=4’b0010,in1^in2,result=4’b0101, overflow=1’d0
opcode=3’d4,
in1=4’b0101,in2=4’b0010,in1+in2,result=4’b0111, overflow=1’d0
opcode=3’d5,
in1=4’b0111,in2=4’b0010,in1-in2,result=4’b0101, overflow=1’d0
opcode=3’d6,
in1=4’b0111,in2=4’b0010,對in1邏輯左移in2個位元,亦即
4’b0111<<2,result=4’b1100,overflow=1’d0
ASIC Lab 4
NCKU EE CAD
9-1 Simple ALU
opcode=3’d7,
in1=4’b0110,in2=4’b0001,對in1邏輯右移in2個位元,亦即
4’b0110>>1,result=4’b0011,overflow=1’d0
※邏輯左/右移時,in2範圍只測4’b0000~4’b0111
ASIC Lab 5
NCKU EE CAD
9-1 Simple ALU
輸入輸出介面:
訊號名稱 輸入/輸出 位元寬度
opcode
in1
in2
input
input
input
3
4
4
overflow
result
output
output
1
4
說明
ALU功能選擇線
ALU輸入1
ALU輸入2
ALU溢位訊號線
ALU運算結果
ASIC Lab 6
NCKU EE CAD
9-1 Simple ALU
硬體電路區塊 :
opcode
in1
in2
3
overflow
4
4
Simple ALU
4
result
ASIC Lab 7
NCKU EE CAD
9-2 擲骰子電路實作(一)
(1) 虛擬裝置
ASIC Lab 8
NCKU EE CAD
9-2 擲骰子電路實作(一)
(2) 功能區塊圖
seg2
顯
示
clk
產
生
亂
數
cnt
抓
取
數
值
num0~num2
seg1
seg0
button_ok
判
斷
led
button
ASIC Lab 9
NCKU EE CAD
9-2 擲骰子電路實作(一)
(3) 亂數產生器說明
clk
產
生
亂
數
cnt
使用一組計數器來當亂數產生器
當clk頻率很高時
每次所抓取到的cnt值都會不同
ASIC Lab 10
NCKU EE CAD
9-2 擲骰子電路實作(一)
(4) 抓取數值說明
cnt
clk
抓
取
數
值
num0~num2
button_ok
button
ASIC Lab 11
NCKU EE CAD
9-2 擲骰子電路實作(一)
(5) 判斷區塊說明
num0~num2
button_ok
判
斷
led
等button_ok的3個位元
都為1時才開始判斷
若num0=num1=num2
則讓led燈亮
ASIC Lab 12
NCKU EE CAD
9-2 擲骰子電路實作(一)
(6) 七階顯示器部份說明
button_ok[0]
num0
cnt
4
4
1
show0
0
4
SevenSeg
seg0
7
在還沒按button之前,
讓七階顯示器顯示亂數
ASIC Lab 13
NCKU EE CAD
9-3 擲骰子電路實作(二)
(1) 虛擬裝置
ASIC Lab 14
NCKU EE CAD
9-3 擲骰子電路實作(二)
(2) 功能說明

亂數限制在1~6之間,可自行決定上數或下數

抓取三組數值

當button尚未按下時,七階顯示器顯示亂數

當三個button皆按下時,判斷:

若三個數字皆相同,則亮兩顆led燈

若只有其中兩個數字相同,則亮一顆led燈

若三個數字皆不相同,則led燈皆不亮
ASIC Lab 15