복습 - 연산자 챌린지
Coddy Verilog 여정의 기초 섹션에 포함된 레슨 — 90개 중 29번째.
챌린지
각 작업에 맞는 올바른 표현식을 작성하여 코드를 완성하세요. 이 챌린지는 이번 장에서 다룬 모든 연산자를 포함합니다.
수행할 작업:
- 논리 연산 (Logical):
value1과value2가 모두 0이 아닌지 확인하고, 그 결과를logic_out에 저장하세요. - 축약 연산 (Reduction):
vector의 모든 비트가 1인지 확인하고, 그 결과를reduction_out에 저장하세요. - 시프트 연산 (Shift):
data를 왼쪽으로 2비트 시프트하고, 그 결과를shift_out에 저장하세요. - 결합 연산 (Concatenation):
high와low를 결합하여 8비트 값을 만들고, 이를concat_out에 저장하세요. - 조건 연산 (Conditional): `a`와 `b` 중 더 큰 값을
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
// Logical
value1 = 4'd6;
value2 = 4'd0;
logic_out = ______; // value1과 value2가 모두 0이 아닌지 확인
// Reduction
vector = 4'b1111;
reduction_out = ______; // Check if all bits of vector are 1
// Shift
data = 8'b00001111;
shift_out = ______; // data를 왼쪽으로 2비트 시프트
// Concatenation
high = 4'b1010;
low = 4'b1100;
concat_out = ______; // high와 low를 결합하여 8비트 값 생성
// Conditional
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