or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Assignment3: Single-cycle RISC-V CPU
contributed by ???
Hello World in Chisel
Set a time unit
CNT_MAX
, and change the value ofio.led
(blkReg
's value) for each time unit to achieve the blinking effect of the LED light.Single Cycle RISC-V CPU
Once the first three files are completed, connect them with other components to form a complete CPU.
InstructionFetch.scala :
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →During the IF (Instruction Fetch) stage, determine the PC source by checking io.jump_flag_id. If a JUMP is not taken, the instructions enter the CPU in their original order, and the next instruction is PC + 4.
Waveform analysis
From the above diagram, it can be observed that with each clock cycle change, the personal computer (PC) will continue to increment by 4 until
io_jump_flag_id
is set to 1 (on the rising edge of the wave). This signifies that the instruction is a jump, and the next instruction will not be PC+4.InstructionDecode.scala
When the opcode of the instruction is type L, which is a LOAD instruction, it is necessary to read the instruction from memory. In this case, set io.memory_read_enable to 1.
When the opcode of the instruction is type S, which is a STORE instruction, it is necessary to write the instruction to memory. In this case, set io.memory_write_enable to 1.
Waveform analysis
From the above diagram, it can be seen that when the opcode is
0x23
, indicating an S-type instruction,io_memory_write_enable
should be set to 1 (on the rising edge of the wave). This signifies that data can be written into memory.Execute.scala
Waveform analysis
io.aluop1_source
determines the first source of the ALU. Whenio.aluop1_source
is set to 1 (on the rising edge of the wave),alu.io.op1
is connected toio.instruction_address
. Whenio.aluop1_source
is set to 0 (on the falling edge of the wave),alu.io.op1
is connected toio.reg1_data
.io.aluop2_source
determines the second source of the ALU. Whenio.aluop2_source
is set to 1 (on the rising edge of the wave),alu.io.op2
is connected toio.immediate
. Whenio.aluop2_source
is set to 0 (on the falling edge of the wave),alu.io.op2
is connected toio.reg2_data
.ALU, as an arithmetic logic unit, performs mathematical operations based on the specified function. The demonstration above illustrates addition. ex:
io_reg1_data
+io_reg2_data
=alu_io_result
CPU.scala :
In the preceding stages, the connections within each component have been roughly established. In
CPU.scala
, simply connecting the inputs and outputs between different components completes a ready-made CPU.Test the assembly code for HW2
Transplant the
test.S
file from HW2 to the target directory. Modify the makefile to convert the.S
file to a.asmbin
file for execution on Chisel. Simultaneously, add a class namedHW2Test
inCPUTest.scala
to test the output oftest.asmbin
.The following is the content of
HW2Test
:The following figure depicts the experimental results.
The original code printed the results through an ecall. In this experiment, a notable difference is that you store the experimental results in the target memory. During testing, you input the corresponding answers at the respective memory locations. If it is "success", it indicates that the experimental results match your expectations.
Waveform analysis
First instruction
ff010113
is assembly code foraddi sp,sp,-16
.addi
is an I-type instruction, so the immediate value is -16 (0xFFFFFFF0).sp
is 0, adding -16 results in -16. Therefore,io_result
andio_regs_write_data
have values of FFFFFFF0.Second instruction
Chisel does not have the
la
instruction. As shown in the diagram, Chisel simulates the functionality ofla
using two instructions:00000297
and26028293
.Third instruction
00512023
is assembly code forsw t0, 0(sp)
.sw
is an S-type instruction, so the immediate value is 0.t0
is 00001264, coming fromio_read_data2
.