KuroPhoenix
    • 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 New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Lab 3 Report 112550019 謝嘉宸 112550047 徐瑋晨 ## Introduction In this lab assignment, our objective is to implement datapath as well as complete the control unit entries, or implement logic for generating remaining control outputs using the cs register for each RISC-V instruction in a single-cycle processor. Our overall approach is study the diagram and figures provided and simultaneously reference the code provided by the TAs to derive the remaining code. ## Design We referenced the given figure, and the code skeleton provided for further insight. ### Datapath #### Mux We change the output of MUX by different input signals from ```pc_mux_sel```. If ```pc_mux_sel``` is ```pm_p```, then it indicates that the current operation is PC increment. If ```pc_mux_sel``` is ```pm_j```, then the instruction is a jump instruction. Same logic for ```pm_b``` (Which is a branching instruction) and ```pm_r``` (Which is JALR (jump register) instruction) #### Register File For connecting inputs to ports in Register File, we referenced the given figure, and added ```inst_rs1``` to address 1, and ```inst_rs2``` to address 2. #### Operand 0 Mux We change the output of operand 0 MUX by different input signals from ```pc_mux_sel```. If ```pc_mux_sel``` is ```am_rdat```, then it indicates that the current operation uses output of bypass mux for rs1. Same logic for ```am_pc``` (Which lets current PC go through), ```am_pc4``` (Which lets PC+4 go through), ```am_0``` (Which lets constant 0 go through), ```am_x``` (Which lets "don't care" term go through) #### Operand 1 Mux We change the output of operand 1 MUX by different input signals from ```pc_mux_sel```. If ```pc_mux_sel``` is ```bm_rdat```, then it indicates that the current operation uses output of bypass mux for rs2. Same logic for ```bm_shamt``` (Which uses shift amount), ```bm_imm_u``` (Which uses U-type immediate), ```bm_imm_sb``` (Which uses SB-type immediate), ```bm_imm_i``` (Which uses I-type immediate), ```bm_imm_s``` (Which uses S-type immediate), ```bm_0``` (Which uses constant 0), ```bm_x``` (Which uses "don't care" term) #### Branch Condition Logic For this, we reference the given TODO instructions and compare ```rf_rdata0``` and ```rf_rdata1``` based different branching instructions. We were especially careful on handling signed and unsigned comparisons. #### Send out memory request For this, we referenced the given figure and observed that the results of ALU should be inputted in the data memory, while `rf_rdata1` only supplies store data; loads are written via the data memory response path. #### Muldiv Result Mux We decide where to put the Muldiv result based on the input signal ```muldiv_mux_sel```. For ```mdm_l```, it means we should put the result into the lower 32 bits of the register. For ```mdm_u```, it means we should put the result into the upper 32 bits of the register. #### Execute Result Mux This Mux is aimed at deciding which result from ALU and Muldiv should be let through. Similarly, the decision is also influenced by the control signal ```execute_mux_sel```. If it equals ```em_alu```, then the results from ALU gets outputted; if it is ```em_md```, then the results from Muldiv gets outputted. #### Data memory subword adjustment mux This Mux decides the position in which to write the value. The decision is influenced by ```dmem_mux_sel```. The control signals represent different datatypes, and we place the values into the register in different positions based on datasize, and also decide whether to add the signed bit. #### Writeback Mux It is aimed at deciding which values to write back to the register file. If control signal ```wb_mux_sel``` is ```wm_alu```, then it writes back the result from ```execute_mux_out```.If control signal ```wb_mux_sel``` is ```wm_mem```, then it writes back the result from ```dmemresp_mux_out``` ### Control Unit To tackle this objective, we referenced the RISC-V instruction manual and simulated the instructions flowing thorough the Datapath to gain more insight on how each control signal might react to each instructions. #### I-type and R-type Instructions All I‑type and R‑type instructions assert their validity bit and leave jumps, branches, and memory operations disabled so that the PC simply advances by four. Both kinds feed the ALU from the register file (so `amux = am_rdat` and `rs1_en = y`), omit any multiply/divide unit involvement (`md_fn = md_x`, `md_en = n`), send the ALU output straight through the execute multiplexer (`ex_muxsel = em_alu`), and write the result back into the register file (`wb_muxsel = wm_alu`, `rf_wen = y`, `rf_wa = rd`). The only real difference is in how the second operand is chosen and whether a second register operand is enabled: I‑types use an immediate (`op1_muxsel = bm_imm_i`) or, for shifts, the shift amount (`op1_muxsel = bm_shamt`) with no second register (`rs2_en = n`), whereas R‑types take both operands from registers (`op1_muxsel = bm_rdat`, `rs2_en = y`). #### Load and Store Instructions Loads and stores follow the same basic pattern for address calculation—`val = y`, no jumps or branches, `amux = am_rdat`, `rs1_en = y`, `op1_muxsel = bm_imm_i`, `alu_fn = alu_add`—but differ in whether they drive or consume data from memory. Loads disable the second register file port (`rs2_en = n`), set the memory operation to load (`mem_op = ld`), choose the data‐memory mask (`dmm`) and width (`ml`), and then route the memory result to the register file (`wm_mem = y`, `wb_muxsel = wm_mem`, `rf_wen = y`). Stores enable the second port to supply store data (`rs2_en = y`), set `mem_op = st`, and leave all writeback signals off (`wm_x`, `rf_wen = n`). #### Jump Instructions Jump instructions also set `val = y` but activate the jump enable bit (`j_en = y`) and select between PC‑plus‑immediate (`pm_j` for JAL) or register‑plus‑immediate (`pm_r` for JALR) as the next PC. Both use the ALU to form the link address by adding four to the PC (`amux = am_pc4`)—JAL does so without reading a register (`rs1_en = n`, `op1_muxsel = bm_0`), while JALR reads its base register (`rs1_en = y`, `op1_muxsel = bm_imm_i`)—and then write that link back into the register file (`wb_muxsel = wm_alu`, `rf_wen = y`, `rf_wa = rd`). #### Branching Instructions Conditional branches leave `j_en` off but encode their test in the branch‑select field (`br_sel`), feed both registers through the ALU with `alu_fn` set to XOR for equality or to the appropriate less‑than test, and choose the branch target vs. PC + 4 via `pc_muxsel = pm_b` when the condition is met. Since they never touch memory or write back results, the execute multiplexer is diverted (`ex_muxsel = em_x`) and all writeback and memory enable signals remain off (`wm_x`, `rf_wen = n`, `mem_op = nr`). #### Muldiv Instructions Multiply‑and‑divide instructions turn on their `val` bit without enabling jumps or branches, take both operands from registers (`amux = am_rdat`, `rs1_en = y`, `op1_muxsel = bm_rdat`, `rs2_en = y`), and hand off computation to the MD unit by setting `md_fn` to one of the multiply or divide codes and `md_en = y`. The execution multiplexer selects the MD result (`em_md`), and the output is treated like any ALU result for writeback (`wb_muxsel = wm_alu`, `rf_wen = y`, `rf_wa = rd`) while memory remains untouched. #### Parse remaining output control signals Finally, the 34‑bit control word is simply sliced into fields that drive all of these decisions. After decoding the branch test into a single “need_branch” signal, the top two bits choose between PC + 4, a branch target, or a jump. The next groups of bits directly wire operand multiplexers and function codes into the ALU and MD units. Memory controls follow, with bits for read/write, width, and response routing, and the final bits steer writeback selection, register‑file enable, and destination register address. ## Testing Methodology For testing, we simply wrote one assembly code for each instruction to check whether each instruction will be handled properly. For R-type and I-type instructions, we design the problems and prepare correct results in advance so that when our implementation code gives the result, we can determine whether the instructions are handled correctly. For B-type instructions, we simply make all the branch conditions to be true and let those instructions branch to the pass label to demonstrate the instruction handled correctly. Therefore, we can determine whether our designs are correct by checking the results. For instructions `j` and `jr`, we check whether the jump work correctly(jump to the correct position of the code), and for the `jalr`, we modified the provided code `riscv-jal` and check both the `rd` value and the position jumped to. ## Conclusion In this lab, we have successfully implemented the datapath and control unit of a single-cycle processor. Particular insights are gained through observing the given figures and the skeleton code. We now possess verilog level understanding of how single-cycle processor works and have learned alot from assigning values to unit control table. We believe this will be a solid foundation on which we can rely on in our future hardware-oriented endeavours.

    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