Refactor: Update comments to Chinese and standardize.

This commit updates all comments in Verilog source files, the Python assembler, and the batch run script to Chinese.

Key changes include:
- Verilog files (.v):
  - Header comments (Description, Features, Revision, Additional Comments) translated and updated.
  - Inline comments translated to Chinese.
  - Removed [FIX], [NEW] tags, incorporating relevant information into the comments.
- assembler.py:
  - Main docstring and inline comments translated to Chinese.
  - Removed [FIX] style tags, with details moved to a revision history in the docstring.
  - Ensured no functional code changes were made.
- run.bat:
  - All user-facing `echo` prompts translated to Chinese.
  - Comments (::) reviewed and standardized in Chinese.

The codebase's logic and functionality remain unchanged. This effort improves readability and maintainability for Chinese-speaking developers by providing comprehensive and standardized documentation directly within the code.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
2025-06-18 18:07:21 +08:00
committed by GitHub
parent 621c973a4a
commit 4bc6285c41
11 changed files with 625 additions and 418 deletions

View File

@@ -16,41 +16,52 @@
** to be fetched. It updates on every clock cycle.
**
** Update Logic:
** - If no branch/jump: PC_next = PC_current + 4
** - If branch/jump taken: PC_next = Branch/Jump Target Address
**
** - 若无分支或跳转 (pcsource=0): PC_next = PC_current + 4
** - 若发生分支或跳转 (pcsource=1): PC_next = PC_current + imm_ext (分支/跳转目标地址)
** (其中 imm_ext 是已经过符号扩展和适当左移的偏移量)
** Features:
** - 32位程序计数器
** - 同步复位功能复位时PC置为0x00000000
** - 在每个时钟上升沿更新PC值
** - 支持顺序执行 (PC + 4)
** - 支持基于立即数偏移量的分支和跳转
** Revision:
** Revision 0.01 - File Created
**
** Revision 0.01 - 文件创建及基本功能实现
** Additional Comments:
** - `imm_ext` 输入假定已经由立即数扩展单元处理过例如对于分支指令已经左移两位
*******************************************************************************/
module pc (
input wire clk, // 时钟 (Clock)
input wire rst, // 复位 (Reset)
input wire pcsource, // PC下一地址来源选择 (PC next address source selection)
input wire [31:0] imm_ext, // 来自立即数扩展单元的偏移量 (Offset from immediate extender)
output reg [31:0] pc_out // 当前PC值 (Current PC value)
input wire clk, // 时钟信号输入
input wire rst, // 复位信号输入 (高有效)
input wire pcsource, // PC下一地址来源选择信号 (0: PC+4; 1: 分支/跳转目标)
input wire [31:0] imm_ext, // 来自立即数扩展单元的32位扩展后立即数 (用作偏移量)
output reg [31:0] pc_out // 输出当前PC值 (即当前指令地址)
);
wire [31:0] pc_plus_4;
wire [31:0] pc_branch;
wire [31:0] pc_next;
wire [31:0] pc_plus_4; // 存储PC + 4的结果
wire [31:0] pc_branch; // 存储分支或跳转目标地址
wire [31:0] pc_next; // 存储下一个PC的值
// PC寄存器
// PC register
// PC寄存器逻辑在时钟上升沿或复位信号有效时更新
always @(posedge clk or posedge rst) begin
if (rst) begin
pc_out <= 32'h00000000; // 复位到0地址
pc_out <= 32'h00000000; // 系统复位时PC清零
end else begin
pc_out <= pc_next;
pc_out <= pc_next; // 否则PC更新为pc_next的值
end
end
// PC更新逻辑
// PC update logic
// PC下一状态逻辑 (组合逻辑)
// 计算PC顺序递增4的值 (指向下一条指令)
assign pc_plus_4 = pc_out + 32'd4;
assign pc_branch = pc_out + imm_ext; // 偏移量已经左移两位
// 计算分支/跳转目标地址imm_ext是带符号的偏移量
// 对于分支指令imm_extender模块已经将其处理为乘以4之后的值即左移两位
assign pc_branch = pc_out + imm_ext;
// 根据pcsource信号选择下一个PC值
// 如果pcsource为1 (表示发生分支或跳转)则pc_next为计算出的目标地址pc_branch
// 如果pcsource为0 (表示顺序执行)则pc_next为pc_plus_4
assign pc_next = pcsource ? pc_branch : pc_plus_4;
endmodule