This document describes a 4-bit Arithmetic Logic Unit (ALU) designed and simulated using structural Verilog. The primary focus is the implementation of the ALU's core functionality through multiplexers, showcasing a clear dataflow from inputs to outputs based on the operation select lines.
The ALU performs eight operations: AND, OR, XOR, addition, subtraction, set-on-less-than, left shift, and right shift.
1. Introduction
An Arithmetic Logic Unit (ALU) is a fundamental component of a computer's central processing unit (CPU). It is responsible for performing arithmetic and bitwise logical operations on integer binary numbers.
This project implements a 4-bit ALU with a modular, structural design approach. The central architectural element is a multiplexer network that routes the result of the required operation to the output.
2. Design and Implementation
The ALU is designed using Verilog HDL with a structural modeling style. The top-level module defines the input/output ports and instantiates lower-level modules that perform specific tasks.
2.1. Inputs and Outputs
The ALU has the following ports:
• Input: A[3:0], B[3:0] - Two 4-bit data operands.
• Input: ALUOp[2:0] - A 3-bit operation code selecting one of eight operations.
• Output: Result[3:0] - The 4-bit result of the operation.
• Output: Zero - A flag set to 1 when Result is equal to zero.
2.2. Core Functional Blocks
The design consists of several parallel functional blocks, each computing a specific operation:
1. Bitwise AND unit.
2. Bitwise OR unit.
3. Bitwise XOR unit.
4. A 4-bit full adder/subtractor unit. This unit performs addition (A+B) or subtraction (A-B) based on a control signal derived from ALUOp. Subtraction is implemented via two's complement addition.
5. A Set-on-Less-Than (SLT) unit. This unit compares A and B as signed numbers. If A < B, the output is 4'b0001; otherwise, it is 4'b0000. The comparison is done by checking the sign bit of the subtraction result (A-B).
6. A left shifter, performing a logical left shift on A by the amount specified in B[1:0] (lower 2 bits).
7. A right shifter, performing a logical right shift on A by the amount specified in B[1:0] (lower 2 bits).
2.3. The Multiplexer Network
All eight 4-bit results from the functional blocks are connected as inputs to an 8-to-1 multiplexer. The ALUOp[2:0] signal acts as the multiplexer's select line, choosing which operation's result is passed to the final Result[3:0] output. This is the central mechanism of the ALU's structural design.
2.4. Zero Flag Generation
The Zero flag is generated by a simple NOR gate tree (or a reduction NOR operation) that checks if all bits of the final Result[3:0] are zero.
3. Simulation and Results
The design was simulated using a testbench that exhaustively tested all operation codes with various input combinations.
3.1. Test Cases
Key test cases included:
• Arithmetic Operations: Testing addition with carry propagation (e.g., 4'b1111 + 4'b0001 = 4'b0000 with carry-out), and subtraction generating negative results (handled correctly by the adder in two's complement mode).
• Logical Operations: Verified AND, OR, XOR for bit patterns like 4'b1010 and 4'b1100.
• Comparison: Tested SLT for signed comparisons (e.g., A=4'b1111 (-1), B=4'b0001 (1) correctly resulted in SLT=1).
• Shifts: Confirmed left and right shifts by 0, 1, 2, and 3 positions.
• Zero Flag: Ensured the Zero flag was correctly set when the result was zero (e.g., A=4'b0101, B=4'b1010, XOR operation).
3.2. Waveform Analysis
The simulation waveforms confirmed that the output Result and the Zero flag updated correctly within the same clock cycle, reflecting the selected operation based on ALUOp. The multiplexer switching behavior was clearly observable as ALUOp changed.
4. Conclusion
A 4-bit ALU was successfully designed and verified using structural Verilog. The multiplexer-based architecture provides a clear and efficient data path for selecting between multiple parallel computed results.
This design demonstrates fundamental digital logic principles, including combinational logic design, multiplexer applications, and binary arithmetic operations. It can serve as a foundational block for more complex processor designs.
Appendix: Verilog Code Structure
The code is organized into the following modules:
• full_adder (1-bit)
• adder_4bit (structural from full_adder)
• adder_subtractor (using adder_4bit and XOR gates for two's complement)
• and_unit, or_unit, xor_unit (bitwise)
• slt_unit (using the adder_subtractor's sign bit)
BNB
ETH
SOL

交易所
交易所排行榜
24小时成交排行榜
人气排行榜
交易所比特币余额
交易所资产透明度证明
去中心化交易所
资金费率
资金费率热力图
爆仓数据
清算最大痛点
多空比
大户多空比
币安/欧易/火币大户多空比
Bitfinex杠杆多空比
ETF追踪
比特币持币公司
加密资产反转
以太坊储备
HyperLiquid钱包分析
Hyperliquid鲸鱼监控
索拉纳ETF
大额转账
链上异动
比特币回报率
稳定币市值
期权分析
新闻
文章
财经日历
专题
钱包
合约计算器
账号安全
资讯收藏
自选币种
我的关注