mirror of
https://github.com/handsomezhuzhu/2025-yatcpu.git
synced 2026-02-20 20:10:14 +00:00
实验一的取指&译码
This commit is contained in:
@@ -52,8 +52,6 @@ class Execute extends Module {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// lab1(Execute) end
|
||||
|
||||
io.mem_alu_result := alu.io.result
|
||||
|
||||
@@ -178,13 +178,25 @@ class InstructionDecode extends Module {
|
||||
)
|
||||
|
||||
// lab1(InstructionDecode)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
io.ex_aluop2_source := Mux(opcode === InstructionTypes.RM,
|
||||
ALUOp2Source.Register,
|
||||
ALUOp2Source.Immediate
|
||||
)
|
||||
// 仅当指令是 Load 类型时,才使能内存读。
|
||||
io.memory_read_enable := opcode === InstructionTypes.L
|
||||
// 仅当指令是 Store 类型时,才使能内存写。
|
||||
io.memory_write_enable := opcode === InstructionTypes.S
|
||||
// 根据指令类型,选择写回寄存器的数据来源。
|
||||
io.wb_reg_write_source := MuxLookup(
|
||||
opcode,
|
||||
RegWriteSource.ALUResult // 默认来源是ALU计算结果
|
||||
)( // 使用新的 MuxLookup 语法
|
||||
IndexedSeq(
|
||||
InstructionTypes.L -> RegWriteSource.Memory, // Load 指令来源是内存
|
||||
Instructions.jal -> RegWriteSource.NextInstructionAddress, // jal/jalr 来源是下一条指令地址 (PC+4)
|
||||
Instructions.jalr -> RegWriteSource.NextInstructionAddress
|
||||
)
|
||||
)
|
||||
// lab1(InstructionDecode) end
|
||||
io.reg_write_enable := (opcode === InstructionTypes.RM) || (opcode === InstructionTypes.I) ||
|
||||
(opcode === InstructionTypes.L) || (opcode === Instructions.auipc) || (opcode === Instructions.lui) ||
|
||||
|
||||
@@ -37,6 +37,12 @@ class InstructionFetch extends Module {
|
||||
io.instruction := io.instruction_read_data
|
||||
// lab1(InstructionFetch)
|
||||
|
||||
when(io.jump_flag_id) {
|
||||
pc := io.jump_address_id
|
||||
}.otherwise {
|
||||
pc := pc + 4.U
|
||||
}
|
||||
|
||||
|
||||
|
||||
// la1(InstructionFetch) end
|
||||
|
||||
Reference in New Issue
Block a user