Combinational Logic

Gates and Small Circuits

  • Half Adder
    Design a half adder circuit using Verilog. A half adder is a combinational circuit that computes the sum of two …
  • Full Adder
    Design a full adder circuit using Verilog. A full adder adds a, b, and cin and outputs sum and cout.
  • Half Subtractor
    Design a half subtractor which subtracts b from a and outputs diff and borrow.
  • Full Subtractor
    Design a full subtractor that subtracts b and bin from a and outputs diff and bout.
  • 2:1 Multiplexer
    Design a 2:1 multiplexer using Verilog with inputs A, B, select S and output Y.
  • 4:1 Multiplexer
    Design a 4:1 Multiplexer circuit in Verilog.
  • 1:2 DeMultiplexer
    Design a 1:2 DeMultiplexer circuit in Verilog.
  • 1:4 DeMultiplexer
    Design a 1:4 DeMultiplexer circuit in Verilog.
  • 2-bit Comparator
    Design a 2-bit Comparator circuit in Verilog. It must have two inputs, a and b. After comparing, it must give …
  • 4-bit Comparator
    Design a 4-bit Comparator circuit in Verilog. It must have two inputs, a and b. After comparing, it must give …
  • Half Adder using MUX
    Design a Half Adder using MUX circuit in Verilog. Use the pre-defined MUX in the user code, and assign appropriate …
  • Half Subtractor using MUX
    Design a Half Subtractor using MUX circuit in Verilog.

Encoders & Decoders

  • 2-to-4 Decoder
    Design a 2-to-4 decoder. The output line corresponding to the input binary number should be high.
  • 3-to-8 Decoder
    Implement a 3-to-8 decoder that sets only one output bit high for each input combination.
  • 4-to-2 Encoder (without priority)
    Design a 4-to-2 encoder that produces a 2-bit binary code corresponding to which input is high.
  • 8-to-3 Encoder (without priority)
    Create an 8-to-3 encoder that outputs the binary code of the active input.
  • Priority Encoder (4-input)
    Design a 4-input priority encoder where the highest-priority active input is encoded.

Code Converters

  • BCD to Excess-3 Converter
    Design a combinational converter from a 4-bit BCD digit to its Excess-3 code. Excess-3 adds 3 to the BCD value, …
  • Excess-3 to BCD Converter
    Design a combinational converter from a 4-bit Excess-3 code back to the BCD digit. Excess-3 is the BCD value plus …
  • Binary to BCD Converter
    Convert an 8-bit unsigned binary number (0 to 255) into three BCD digits using the shift-and-add-3 (double dabble) algorithm: shift …
  • Binary to Gray Converter
    Convert a 4-bit binary number to Gray code. The most significant Gray bit equals the binary MSB; every other Gray …
  • Gray to Binary Converter
    Convert a 4-bit Gray code back to binary. The binary MSB equals the Gray MSB; each lower binary bit is …

Arithmetic Circuits

  • 4-bit Ripple Carry Adder
    Design a 4-bit ripple carry adder: four full adders chained so that the carry out of each bit feeds the …
  • 4-bit Adder-Subtractor
    Design a 4-bit adder-subtractor controlled by a single line: when sub is 0 the circuit computes a + b; when …
  • 4-bit Carry Lookahead Adder
    Design a 4-bit carry lookahead adder. Compute generate g = a & b and propagate p = a ^ b …
  • 2's Complement Generator
    Design a circuit that outputs the two's complement of a 4-bit input: invert every bit and add 1, which negates …
  • 4-bit Binary Multiplier
    Design an unsigned 4-bit by 4-bit multiplier producing an 8-bit product. A structural approach forms the four partial products (each …

Comparators and Detectors

  • Even Parity Generator
    Generate an even parity bit for an 8-bit data word: parity is 1 when the data has an odd number …
  • Even Parity Checker
    Check an 8-bit data word that arrived with an even parity bit. The error output is 1 when the nine …
  • Odd Parity Generator
    Generate an odd parity bit for an 8-bit data word: parity is 1 when the data has an even number …
  • Bitwise Equality Comparator
    Compare two 4-bit words bit by bit. eq[i] is 1 when a[i] equals b[i] (an XNOR per bit), and all_eq …
  • 4-bit Magnitude Comparator (gates only)
    Compare two unsigned 4-bit numbers using only logic gates (AND, OR, NOT, XOR): no relational operators. Work from the MSB …

Custom logic functions

  • Majority Detector (3-input and 5-input)
    Write two modules. majority3 outputs 1 when at least two of its three inputs are 1. majority5 outputs 1 when …
  • Minority Detector (4-input)
    Output 1 when the ones are in the minority among four inputs, i.e. when at most one of the four …
  • 7-segment Display Decoder
    Decode a BCD digit to the seven segments of a common-cathode display (segments light when their bit is 1). The …
  • 5-input Voter
    Five voters each cast a yes (1) or no (0). Output the number of yes votes and whether the motion …
  • Alarm System Logic
    A home alarm has three sensors (door, window, motion) and two settings (armed, night). The alarm sounds only when the …

Logic Puzzles & Circuits

  • Logic Lock (4-bit key comparator)
    A lock opens only when it is enabled and the entered key matches the stored code bit for bit. Inputs: …
  • Traffic Light Controller (combinational phase)
    Given the current phase of a two-way junction, drive the north-south and east-west lights. Each light output is {red, yellow, …
  • 4-bit Barrel Shifter
    Rotate a 4-bit word by 0 to 3 positions in either direction. Rotation wraps the bits that fall off one …
  • Multiply by 2, 4 and 8 with shifts
    Produce three products of an 8-bit unsigned input using left shifts: times2 = in << 1, times4 = in << …
  • Divide by 2, 4 and 8 with shifts
    Produce three integer quotients of an 8-bit unsigned input using right shifts: div2 = in >> 1, div4 = in …

Bus and Priority Logic

  • 2-device Priority Bus Arbiter
    Two devices request a shared bus. Grant it to at most one of them: device 0 has priority, so when …
  • Tri-state Buffer Bus
    Two 4-bit sources share one bus through tri-state buffers. When en_a is 1 the bus carries data_a; when en_b is …
  • Simple ALU (2-bit opcode)
    A 4-bit ALU with four operations selected by a 2-bit opcode: 00 add, 01 subtract, 10 AND, 11 OR. Results …
  • ALU with AND, OR, XOR and ADD
    A 4-bit ALU with a carry output: opcode 00 AND, 01 OR, 10 XOR, 11 ADD. cout is the carry …
  • Average of Two Numbers
    Output the integer average of two unsigned 4-bit numbers: (a + b) / 2, rounding down. Add in 5 bits …

Data Routing

  • 2x2 Crossbar Switch
    Route two 4-bit inputs to two outputs. With sel = 0 the connection is straight (out0 = in0, out1 = …
  • Bit Reverser
    Reverse the bit order of an 8-bit word: out[7] = in[0], out[6] = in[1], and so on, so 10100000 becomes …
  • Parity Bit Appender
    Extend a 7-bit data word to 8 bits by appending an even parity bit as the new most significant bit, …
  • LED Pattern Generator
    Drive eight LEDs with a pattern chosen by a 3-bit selector: 000 all off, 001 all on, 010 alternating 10101010, …
  • Parametrised Function Y = A.B + C.D
    Implement y = (a AND b) OR (c AND d) bit by bit, for a bus width given by a …