https://github.com/dlwotjr/HDL_Bits
GitHub - dlwotjr/HDL_Bits
Contribute to dlwotjr/HDL_Bits development by creating an account on GitHub.
github.com
https://hdlbits.01xz.net/wiki/Main_Page
HDLBits
HDLBits — Verilog Practice HDLBits is a collection of small circuit design exercises for practicing digital hardware design using Verilog Hardware Description Language (HDL). Earlier problems follow a tutorial style, while later problems will increasingl
hdlbits.01xz.net
1-1-1. 문제 : Simple Wire
module top_module( input in, output out );
assign out = in;
endmodule
1-1-2. 문제 : Four Wires
module top_module(
input a,b,c,
output w,x,y,z );
assign {w,x,y,z} = {a,b,b,c};
//assign w = a;
//assign x = b;
//assign y = b;
//assign z = c;->이런식으로 하는 것도 가능하지만 위의 것이 더 짧으니까 좋다
endmodule
1-1-3. 문제 : Inverter
- 비트 연산자 ~(Not)과 논리 연산자(Not -> !)
- 이것의 차이는 비트 연산자의 경우 비트 단위로 동작하며 여러 비트의 입력에 대해서도 각 비트 반전을 시킴
- 논리 연산자는 다중 비트 입력에 대해서는 전체값을 0 또는 1로 간주해 처리함
module top_module( input in, output out );
assign out = ~in;
endmodule
1-1-4. 문제 : AND Gate
module top_module(
input a,
input b,
output out );
assign out = a&b;
endmodule
1-1-5. 문제 : NOR Gate
module top_module(
input a,
input b,
output out );
assign out = ~(a|b); //-> a~|b해도 됨
endmodule
1-1-6. 문제 : XNOR Gate
module top_module(
input a,
input b,
output out );
assign out = ~(a^b); //-> a~^b해도 됨
endmodule
1-1-7. 문제 : Declaring Wires
`default_nettype none
module top_module(
input a,
input b,
input c,
input d,
output out,
output out_n );
wire net_ab; // wire 변수 선언
wire net_cd; // wire 변수 선언
assign net_ab = a & b; // wire 변수에 값 할당 wire net_ab = a & b;이렇게 하면 할당과 선언 동시에 가능
assign net_cd = c & d; // wire 변수에 값 할당
assign out = net_ab | net_cd;
assign out_n = ~out;
endmodule
1-1-8. 문제 : 7458 Chip
module top_module (
input p1a, p1b, p1c, p1d, p1e, p1f,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
wire net_p2ab = p2a & p2b;
wire net_p2cd = p2c & p2d;
assign p2y = net_p2ab | net_p2cd;
wire net_p1abc = p1a & p1b & p1c;
wire net_p1def = p1d & p1e & p1f;
assign p1y = net_p1abc | net_p1def;//할당시 assign 빼먹으면 안대
endmodule