復習 - 演算子チャレンジ
CoddyのVerilogジャーニー「基礎」セクションの一部 — レッスン 29/90。
チャレンジ
各タスクに対して正しい式を記述し、コードを完成させてください。このチャレンジは、この章のすべての演算子をカバーしています。
作業内容:
- Logical:
value1とvalue2の両方が non-zero であるか確認し、logic_outに格納します - Reduction:
vectorの all の bit が 1 であるか確認し、reduction_outに格納します - Shift:
dataを left に 2 bits シフトし、shift_outに格納します - Concatenation:
highとlowを Combine して8ビット値にし、concat_outに格納します - Conditional: `a` と `b` のうち larger な方を
cond_outに格納します
自分で試してみよう
module operator_challenge;
reg [3:0] value1, value2;
reg logic_out;
reg [3:0] vector;
reg reduction_out;
reg [7:0] data;
reg [7:0] shift_out;
reg [3:0] high, low;
reg [7:0] concat_out;
reg [3:0] a, b;
reg [3:0] cond_out;
initial begin
// 論理
value1 = 4'd6;
value2 = 4'd0;
logic_out = ______; // value1 と value2 の両方が非ゼロかどうかを確認
// リダクション
vector = 4'b1111;
reduction_out = ______; // Check if all bits of vector are 1
// Shift
data = 8'b00001111;
shift_out = ______; // data を2ビット左シフト
// 連結
high = 4'b1010;
low = 4'b1100;
concat_out = ______; // high と low を結合して8ビットの値にする
// 条件
a = 4'd7;
b = 4'd12;
cond_out = ______; // `a` と `b` の大きい方を格納
$display("6 && 0 = %d", logic_out);
$display("&4'b1111 = %d", reduction_out);
$display("00001111 << 2 = %b", shift_out);
$display("{1010, 1100} = %b", concat_out);
$display("max(7, 12) = %d", cond_out);
$finish;
end
endmodule