一位比較器,數(shù)值比較器的作用和原理是什么?
一、數(shù)值比較器的定義及功能
在數(shù)字系統(tǒng)中,特別是在計算機(jī)中都具有運(yùn)算功能,一種簡單的運(yùn)算就是比較兩個數(shù)A和B的大小。數(shù)值比較器就是對兩數(shù)A、B進(jìn)行比較,以判斷其大小的邏輯電路。比較結(jié)果有A>B、A<B以及A=B三種情況。
1.一位數(shù)值比較器
1位數(shù)值比較器是多位比較器的基礎(chǔ)。當(dāng)A和B都是1位數(shù)時,它們只能取0或1兩種值,由此可寫出1位數(shù)值比較器的真值表:
由真值表得到如下邏輯表達(dá)式:
由以上邏輯表達(dá)式可畫出如下圖所示的邏輯電路。實(shí)際應(yīng)用中,可根據(jù)具體情況選用邏輯門。
下面是實(shí)現(xiàn)的代碼
1、門級描述
module compare_test;
wire AgtB, AeqB, AltB;
reg A, B;
initial
begin
A=0;B=0;
#10 A=0;B=1;
#10 A=1;B=0;
#10 A=1;B=1;
#10 $stop;
end
compare compare_test (AgtB, AeqB, AltB, A, B);
endmodule文章來源:http://www.zghlxwxcb.cn/news/detail-448688.html
2、數(shù)據(jù)流級描述
module compare_df(
input A,B,
output wire AgtB, AeqB, AltB);
assign AgtB=(A*~B);
assign AeqB=(A*B)|(AB);
assign AltB=(~AB);
endmodule
3、行為級描述
module Comparator(
input wire [7:0] a, // ?較數(shù)
input wire [7:0] b, // ?較數(shù)
output reg result, // ?較結(jié)果
output reg equal // ?較結(jié)果
);
// ?為描述
always @(a or b) begin
if(a > b)
{equal,result} <= 2’b01; // a ? b ?
else begin
if(a < b)
{equal,result} <= 2’b00; // a ? b ?
else
{equal,result} <= 2’b10; // 相等
end
end
endmodule
之后用Quartus和modelsim仿真,仿真結(jié)果如下。文章來源地址http://www.zghlxwxcb.cn/news/detail-448688.html
到了這里,關(guān)于一位比較器【模電實(shí)驗(yàn)】的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!