实验一的取指&译码

This commit is contained in:
2025-10-09 19:29:06 +08:00
parent 5a00801875
commit abc354e758
9 changed files with 67 additions and 9 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

9
.idea/2025-fall-yatcpu-repo.iml generated Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View File

@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="temurin-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/2025-fall-yatcpu-repo.iml" filepath="$PROJECT_DIR$/.idea/2025-fall-yatcpu-repo.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -52,8 +52,6 @@ class Execute extends Module {
// lab1(Execute) end // lab1(Execute) end
io.mem_alu_result := alu.io.result io.mem_alu_result := alu.io.result

View File

@@ -178,13 +178,25 @@ class InstructionDecode extends Module {
) )
// lab1(InstructionDecode) // 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 // lab1(InstructionDecode) end
io.reg_write_enable := (opcode === InstructionTypes.RM) || (opcode === InstructionTypes.I) || io.reg_write_enable := (opcode === InstructionTypes.RM) || (opcode === InstructionTypes.I) ||
(opcode === InstructionTypes.L) || (opcode === Instructions.auipc) || (opcode === Instructions.lui) || (opcode === InstructionTypes.L) || (opcode === Instructions.auipc) || (opcode === Instructions.lui) ||

View File

@@ -37,6 +37,12 @@ class InstructionFetch extends Module {
io.instruction := io.instruction_read_data io.instruction := io.instruction_read_data
// lab1(InstructionFetch) // lab1(InstructionFetch)
when(io.jump_flag_id) {
pc := io.jump_address_id
}.otherwise {
pc := pc + 4.U
}
// la1(InstructionFetch) end // la1(InstructionFetch) end