林家葦
    • 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
      • Invitee
    • 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
    • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
Invitee
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
1
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Lab1: R32I Simulator ###### tags: `Computer Architecture` ## souce code ![](https://i.imgur.com/thqCF9a.png) ![](https://i.imgur.com/aIwSJiZ.png) ``` = .data str1: .string " reversei bit is " example: .4byte 0x12345678 shift1: .4byte 0xffff0000 shift2: .4byte 0xff00ff00 shift3: .4byte 0xf0f0f0f0 shift4: .4byte 0xcccccccc shift5: .4byte 0xaaaaaaaa .text main: lw a0,example jal bitreverse lw a1,example jal print li a0,10 ecall bitreverse: lw t3,shift1 and t1,a0,t3 srli t1,t1,16 srli t3,t3,16 and t2,a0,t3 slli t2,t2,16 or t0,t1,t2 lw t3,shift2 and t1,t0,t3 srli t1,t1,8 srli t3,t3,8 and t2,t0,t3 slli t2,t2,8 or t0,t1,t2 lw t3,shift3 and t1,t0,t3 srli t1,t1,4 srli t3,t3,4 and t2,t0,t3 slli t2,t2,4 or t0,t1,t2 lw t3,shift4 and t1,t0,t3 srli t1,t1,2 srli t3,t3,2 and t2,t0,t3 slli t2,t2,2 or t0,t1,t2 lw t3,shift5 and t1,t0,t3 srli t1,t1,1 srli t3,t3,1 and t2,t0,t3 slli t2,t2,1 or t0,t1,t2 mv a0,t0 ret print: mv t0,a0 li a0,1 ecall la a1,str1 li a0,4 ecall mv a1,t0 li a0,1 ecall ret ``` ## **Function Description** * The function of this code will reverse bit. * For example | | original | reverse | | -------- | -------- | -------- | | HEX | 0x12345678 | 0x1E6A2C48 | |Binary|‭0001 0010 0011 0100 0101 0110 0111 1000|0001 1110 0110 1010 0010 1100 0100 1000| |DEC|‭305419896‬|‭510274632‬| ## **Pipeline** * Pipeline can increase the output throughput rate. But pipeline has data dependency issue and branch issue. We can use forwarding unit to solve data dependency. But branch issue is more complex than data dependency. So we have two option to solve this problem. One is always take next instruction ,but if it is wrong we will waste two cycle (one cycle if the branch instruction decides to whether branch on ID stage ). Another is add new hardware,that is, branch predict , but branch predict can't solve branch issue completely. * Briefly introduce five-stage pipeline * IF * Fetch Instruction according to program counter and write instruction which is from instruction memory into IF/ID register. * If load-use happens,we must stall pipeline,because we want to delay next instruction. We must flush instruction and not write next instruction counter into program counter and we can't write flush instruction into IF/ID register in order to ensure we can get previous instruction which unexecuted. * If branch error happens, we just flush instruction,because the wrong instruction count go into program counter,and we will get error instruction. So we just flush instruction and let it go into IF/ID register. * ID * Decoder Instruction which come from IF/ID register. * If load-use happenes, we don't write the result which come from decoding instruction. Because after decoding instruction ,we find the data which we need is not prepare,we need wait one cycle. After we wait one cycle, the data which we need is forwarding to EXE stage,and this instruction will also move to EXE stage. So we can get correct data. * If branch error happens, we don't write the result which come frm decoding instruction. Because this instruction is error, we can't let it move to next stage. * EXE * In this stage, we just execute the instruction according to instruction opcode and func3. * If data dependency happens, we just forwarding data which previous instructions execute result to this stage. * And in this stage we will check load-use,data dependency or branch whether happen. * MEM * This stage will store the result which executed into memory,get data from memory or go to next stage, according to instruction opcode. * This stage can forwarding data to EXE stage,if data dependency exists in MEM stage and EXE stage. * WB * This stage will write the result into register file. * This stage can forwarding data to EXE stage,if data dependency exists in WB stage and EXE stage. * Introduce the bitreverse * **Observed instruction 13** ``` =13 jal bitreverse lw a1,example jal print ``` * when execute instruction 13 ,the next instruction 13 and 14 will enter pipeline.But we don't need to execute the instruction after instruction 13. We need to execute instruction 19 after executing instruction 13. So we must stall the pipeline in order to ensure the sequence of instruction is correct. ![](https://i.imgur.com/DkzP6dm.png) ![](https://i.imgur.com/M8rRmFU.png) ![](https://i.imgur.com/dsAltjt.png) * According to above Figure,when decide whether branch on EXE stage, we must throw out two instructions.And one instruction will be replaced by nop instruction, and another instruction will never move to next stage and will be replaced by next instruction. * **Observed instruction 19 and 20** ``` =19 lw t3,shift1 and t1,a0,t3 srli t1,t1,16 ``` * it exists load-use , so we must stall one cycle. ![](https://i.imgur.com/H5Sw8bQ.png) ![](https://i.imgur.com/4bj4EiH.png) * when lw instruction on EXE stage, hazard controller will find load-use between lw instruction and and instruction. So it will post signal to inform IF stage don't write next instruction counter into Program Counter,prevent current instruction on IF stage and instruction count go into IF/ID stage and to inform ID stage flush the IF/EXE register. ![](https://i.imgur.com/WHMSZnb.png) ![](https://i.imgur.com/6aj1IWJ.png) ![](https://i.imgur.com/oFGjmL2.png) ![](https://i.imgur.com/EdVs6SD.png) ## **Problem** * I don't know how to print next line in Ripes and print integer in hex format

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