XianTon
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Assignment3: Single-cycle RISC-V CPU contributed by < [`RayChen`](https://github.com/padaray) > ## Environment Issue When executing the `sbt -version` command in the terminal of VSCode, the response is correct. ``` sbt version in this project: 1.9.7 sbt script version: 1.9.7 ``` When executing `sbt test` the following error occurs. ``` [error] /home/ray870317/java/jdk/ca2023-lab3/src/main/scala/riscv/core/ALU.scala:6:8: not found: object chisel3 [error] import chisel3._ [error] ^ ``` Initially, I thought that the "build.sbt" file was not properly configured, causing it to be unable to recognize the `import chisel3`. Last, it was discovered that opening the folder in VSCode needs to be done from the root directory `/java/jdk/ca2023-lab3`. </br> ## Operation of ‘Hello World in Chisel’ ```scala // Hello World in Chisel class Hello extends Module { val io = IO(new Bundle { val led = Output(UInt(1.W)) }) val CNT_MAX = (50000000 / 2 - 1).U; val cntReg = RegInit(0.U(32.W)) val blkReg = RegInit(0.U(1.W)) cntReg := cntReg + 1.U when(cntReg === CNT_MAX) { cntReg := 0.U blkReg := ~blkReg } io.led := blkReg } ``` 1. `led` is an unsigned integer output with a width of 1 bit 2. `CNT_MAX` is a constant with a value of 24999999 3. `cntReg` and`blkReg` are both unsigned integers with widths of 32 bits and 1 bit 4. `cntReg` increments by 1 for each cycle. When it reaches 24999999, it resets to 0, and simultaneously, `blkReg` is inverted. 5. Assigns the value of `blkReg` to the output `io.led`. In conclusion, this code appears to make the led flash once every 24999999 cycles. </br> **Enhance operation by incorporating logic circuit** ```scala class Hello extends Module { val io = IO(new Bundle { val led = Output(UInt(1.W)) }) val CNT_MAX = (50000000 / 2 - 1).U; val cntReg = RegInit(0.U(32.W)) val blkReg = RegInit(0.U(1.W)) cntReg := Mux(cntReg === CNT_MAX,0.U,cntReg + 1.U) blkReg := Mux(cntReg === CNT_MAX,~blkReg,blkReg) io.led := blkReg } ``` </br> ## Complete Lab3 and Test After completing lab3 with the filled-in code, we need to run tests using the test files located under the directory `/ca2023-lab3/src/test/scala/riscv/singlecycle`, and I will explain the testing process using Waveform. The waveform file is generated using the following command : ``` $ WRITE_VCD=1 sbt test ``` generated `.vcd` file will store at `/ca2023-lab3/test_run_dir` </br> ### **InstructionFetchTest** **Code Behavior :** &emsp;&emsp; We have a random constant, either 0 or 1. When the is constant equal to 0, `jump_flag_id` set False, and `instruction address` is incremented by 4; When the constant is 1, `jump_flag_id` set True, and `instruction address` jumps to 0x1000. These actions are repeated 100 times. **Waveform Analysis :** - Initial part : ![image](https://hackmd.io/_uploads/SyEpG4LBa.png) &emsp;&emsp; At the beginning, we initialize the value. The `instruction_valid` is set after one clock cycle, and the program starts executing instructions sequentially after a delay of 5 ps. I don't understand why this delay exists. - case 0 : ![image](https://hackmd.io/_uploads/r1l0BNLSp.png) &emsp;&emsp; When constant equal to 0, `jump_flag_id` is set to 0 (False), and the instruction address changes from 0x1000 to 0x1004, without performing a jump action. - case 1 : ![image](https://hackmd.io/_uploads/SJ3_DNLrT.png) &emsp;&emsp; When constant equal to 1, `jump_flag_id` is set to 1 (True), and the instruction address from 0x1010 jump back to 0x1000. ### **InstructionDecoderTest** **Code Behavior :** &emsp;&emsp; We sequentially inputs `sw`, `lui`, and `add` instructions while checking the signals of `ex_aluop1_source`, `ex_aluop2_source`, `regs_reg1_read_address`, and `regs_reg2_read_address` to verify if these four variables behave as expected. **Waveform Analysis :** - sw instruction : ![image](https://hackmd.io/_uploads/rkp2A4Urp.png) &emsp;&emsp; "0x00a02223" address represents the `sw` instruction. We can observe that the `memory_read` signal is 0, and the `memory_write` signal is 1, indicating that data can be written to memory. - lui instruction : ![image](https://hackmd.io/_uploads/ByJ6Hr8ra.png) &emsp;&emsp; "0x00a02223" address represents the `lui` instruction. The `aluop1` signal matches the expected value 1. `memory_read` and `memory_write` are both 0, indicating there is no memory access. ### **ExecuteTest** **Code Behavior :** &emsp;&emsp; Testing whether the ALU functions correctly. The test includes `add` and `beq` instructions. For the `add` instruction, it verifies if the sum of two values is correct. In the case of the beq instruction, it tests whether if_jump_flag is set to 1 when the two values are equal. **Waveform Analysis :** ![image](https://hackmd.io/_uploads/H1qN3r8rT.png) &emsp;&emsp; the sum of `op1` and `op2` equals result, indicating that our calculation result is correct. When `func` is 1, it corresponds to the `add` instruction. ### **FibonacciTest** **Code Behavior :** &emsp;&emsp; Execute the fibonacci.asmbin with the CPU and verify if the values stored in the memory locations it occupies match our expected values.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    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.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully