Recap - Operator Challenge
CoddyのVerilogジャーニー「基礎」セクションの一部。レッスン 29/90。
チャレンジ
各タスクに対して正しい式を書き、コードを完成させてください。このチャレンジでは、この章のすべての演算子を扱います。
実行すること:
- Logical:
value1とvalue2の both が non-zero か確認し、結果をlogic_outに格納します - Reduction:
vectorの all bits が 1 か確認し、結果をreduction_outに格納します - Shift:
dataを 2 bits left にシフトし、結果をshift_outに格納します - Concatenation:
highとlowを 8-bit の値に Combine し、結果を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基礎のすべてのレッスン
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic自分で練習してみよう: Verilogオンラインコンパイラ