Recap - Operator Challenge
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 29번째.
챌린지
각 작업에 맞는 올바른 표현을 작성하여 코드를 완성하세요. 이 챌린지에서는 이 장의 모든 연산자를 다룹니다.
수행할 작업:
- Logical:
value1과value2가 모두 0이 아닌지 확인하고, 그 결과를logic_out에 저장하세요. - Reduction:
vector의 all bits가 1인지 확인하고, 그 결과를reduction_out에 저장하세요. - Shift:
data를 왼쪽으로 2 bits만큼 Shift하고, 그 결과를shift_out에 저장하세요. - Concatenation:
high와low를 8비트 값으로 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가 모두 0이 아닌지 확인
// 리덕션
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 컴파일러