柳嘉祐
IF:Fetch the instruction and update the program counter.
ID:Decode the instruction and read the registers.
EX:Execute the operation or compute the address.
MEM:Access memory (such as loading or storing data).
WB:Write the result back to the register.
IF_ID reg:Store the data from the IF stage and pass it to the ID stage.
ID_EX reg:Store the data from the ID stage and pass it to the EX stage.
EX_MEM reg:Store the data from the EX stage and pass it to the MEM stage.
MEM_WB reg:Store the data from the MEM stage and pass it to the WB stage.
Classify instructions based on opcode and funct.
If the add instruction has not yet completed writing back to x1, and the sub instruction already requires the value of x1, a data hazard will occur.
Forwarding allows the sub instruction to directly obtain the result from the ALU output of the add instruction during the EX stage or from MEM stage, instead of waiting for the add instruction to complete the WB stage and then reading from the register.
If it is certain that the value will be written back to the register, and the rd register is not zero and the MEM rd equals EX rs (1 or 2), the forwarding bit is set to 2'b10.
If it is certain that the value will be written back to the register, the rd register is not zero, the WB rd equals EX rs (1 or 2), and it is confirmed that there is no forwarding from MEM, the forwarding bit is set to 2'b01.
forwarding bit | forwarding from | forwarding to |
---|---|---|
2'b00 | non | non |
2'b10 | mem | ex |
2'b01 | wb | ex |
Perform calculations for each category using the ALU based on the classification.
This code implements Load-Use Hazard detection. When a memory load instruction has not completed its write-back and the next instruction depends on its result, it activates Forwarding or Stalling control signals to ensure data consistency and prevent instruction execution errors.
result
1.Unsupported Compiler
You might be using the standard GCC for x86 or another platform to compile RISC-V code, but this GCC does not recognize the -march and -mabi options because these options are specific to the RISC-V target.
2.Compiler Prefix Error
The compile command might be using gcc instead of the cross-compiler, such as riscv32-unknown-elf-gcc.
environment
set
But encounter space-related issues
build