Assignment3: Single-Cycle RISC-V CPU

Contributed by dcciou

You MUST write in English.

complete code

After fullfilled all blank, it showed:

[info] FibonacciTest:

[info] Single Cycle CPU

[info] - should recursively calculate Fibonacci(10)

[info] ExecuteTest:

[info] Execution of Single Cycle CPU

[info] - should execute correctly

[info] InstructionFetchTest:

[info] InstructionFetch of Single Cycle CPU

[info] - should fetch instruction

[info] ByteAccessTest:

[info] Single Cycle CPU

[info] - should store and load a single byte

[info] InstructionDecoderTest:

[info] InstructionDecoder of Single Cycle CPU

[info] - should produce correct control signal

[info] RegisterFileTest:

[info] Register File of Single Cycle CPU

[info] - should read the written content

[info] - should x0 always be zero

[info] - should read the writing content

[info] QuicksortTest:

[info] Single Cycle CPU

[info] - should perform a quicksort on 10 numbers

[info] Run completed in 47 seconds, 682 milliseconds.

[info] Total number of tests run: 9

[info] Suites: completed 7, aborted 0

[info] Tests: succeeded 9, failed 0, canceled 0, ignored 0, pending 0

[info] All tests passed.

[success] Total time: 68 s (01:08), completed Nov 27, 2023 8:45:17 PM

you can find my code here

myCPU

The original way used the same register and performed an ecall after the calculation, without actually storing the three pieces of data. For the convenience of CPU testing, I have modified it to store the data on the stack, ensuring that the data is stored at 0x04, 0x08, 0x0a.

//add in main part
li sp, 0x0C 

//add in count_one part, before bnez t0,loop

 sw a6, 0(sp)     
 addi sp, sp, -4

During the conversion process, the following issue occurred because the makefile only converts .S files and not .s files.

make: *** No rule to make target 'hw2.asmbin', needed by 'update'. 

Then, I added a test for hw2 within cputest, which involves verifying the success of the calculation (you can find my code on GitHub).

The results are as follows:

[info] HW2Test:

[info] Single Cycle CPU

[info] - should count the number of one

[info] Run completed in 15 seconds, 321 milliseconds.

[info] Total number of tests run: 1

[info] Suites: completed 1, aborted 0

[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0

[info] All tests passed.


Select a repo