Writing The Testbench
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 45번째.
챌린지
이제 half adder가 올바르게 작동하는지 test해야 합니다. initial 블록 안에 test 코드를 추가하세요.
중요: test를 추가하기 전에 test가 제대로 작동할 수 있도록 module 포트를 변경해야 합니다.
해야 할 일:
1단계: 포트 선언 변경
input a, b를reg a, b로 변경하세요(세미콜론 사용).output sum, carry를wire sum, carry로 변경하세요(세미콜론 사용).- module 포트를 완전히 제거하세요(module에
( )가 없어야 합니다).
2단계: test 코드 추가
initial begin블록을 추가하세요.- 블록 안에 다음을 추가하세요.
$display("a b | sum carry");
a = 0; b = 0; #1 $display("%d %d | %d %d", a, b, sum, carry);
a = 0; b = 1; #1 $display("%d %d | %d %d", a, b, sum, carry);
a = 1; b = 0; #1 $display("%d %d | %d %d", a, b, sum, carry);
a = 1; b = 1; #1 $display("%d %d | %d %d", a, b, sum, carry);
- test를 종료하려면 끝에
$finish;를 추가하세요. - initial 블록을 닫으려면
end를 추가하세요.
직접 해보기
module half_adder (
input a,
input b,
output sum,
output carry
);
assign sum = a ^ b;
assign carry = a & b;
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 컴파일러