IMOK
    • 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
    --- type: slide --- <style> .command { display: inline-block; font-size: 24px; color: black; background-color: white; padding: 7px; border-radius: 10px; margin: 5px; } </style> ## 計算機概論Lab-5 ##### HARDWARE ARCHITECTURE AND DATA MANIPULATION ![image](https://hackmd.io/_uploads/HJPZqstkye.png) <p>https://hackmd.io/@IMOK/Lab5</p> --- <img src="https://hackmd.io/_uploads/ryUSIqnJT.jpg" width=400 style="border-radius:1000px;"/> 講師: 賴昱有 --- ![image](https://hackmd.io/_uploads/HJPF9jYkJl.png) --- #### 程式語言對於硬體的抽象程度 + <font size=6>機器語言(低) </font> * <div style="display:inline-block; font-size:24px; color:black; background-color:white;padding: 7px;border-radius: 10px;"> 0010111010100100 </div> + <font size=6> 組合語言</font> * <div style="display:inline-block; font-size:24px; color:black; background-color:white;padding: 7px;border-radius: 10px;"> MOVE R0, R5 </div> + <font size=6> 高級語言(高)</font> * <div style="display:inline-block; font-size:24px; color:black; background-color:white;padding: 7px;border-radius: 10px;"> int a = 0; </div> --- ## 組合語言 <font size =5>通常組成形式為</font> <div style="display:inline-block; font-size:24px; color:black; background-color:white;padding: 7px;border-radius: 10px;"> 指令 [參數一][, 參數二][, 參數三]</div> <br> <font size =5>e.g.</font> <div style="display:inline-block; font-size:24px; color:black; background-color:white;padding: 7px;border-radius: 10px;"> ADDI R2, R0, R1 </div> ---- ### 簡單的加法 #### 組合語言: ``` LOAD R0, [0x60] LOAD R1, [0x61] ADDI R2, R0, R1 STORE R2, [0x62] HALT ``` #### 對應解釋: ```= 將記憶體 60 中的值 load 到 Register R0 中 將記憶體 61 中的值 load 到 Register R1 中 將 Register R0 及 R1 整數相加後存到 Register R2 中 將 Register R2 的值存回記憶體 62 中 停止 ``` --- <img src="https://hackmd.io/_uploads/Hk2Gy-9y1x.png" width=700/> ---- <img src="https://hackmd.io/_uploads/Skdt1Z9JJx.png" width=300/> ---- <img src="https://hackmd.io/_uploads/HkXqCe51kl.png" width=200/> #### Program counter(PC) <font size=5>address of next instruction</font> <br> #### Instruction register(IR) <font size=5>current instruction</font> --- 指令表 僅限於今天會使用到的模擬軟體 實際上的組合語言會有多種不同指令集 R, S, T 皆代表 Register ---- <style> table { width: 85%; border-collapse: collapse; line-height: 2; /* 行距 */ } th, td { font-size: 24px; /* 字體大小 */ } </style> | 指令 | 解釋 | | --------------- | ------------------------------------------------- | | LOAD R, [0xXY] | 將記憶體 XY 中的值填入 Register R | | LOAD R, XY | 將值 XY 填入 Register R | | STORE R, [0xXY] | 將 Register R 的值存入記憶體 XY 中 | | MOVE S, R | 將 Register R 的值存入 Register S 中 | | ADDI R, S, T | 將 Register S 及 T 整數相加後存到 Register R 中 | | ADDF R, S, T | 將 Register S 及 T 浮點數相加後存到 Register R 中 | | OR R, S, T | 將 Register S 及 T 做 OR 後存到 Register R 中 | | AND R, S, T | 將 Register S 及 T 做 AND 後存到 Register R 中 | | XOR R, S, T | 將 Register S 及 T 做 XOR 後存到 Register R 中 | | ROR R, X | 將 Register R 中的值 Rotate X 次 | ---- <style> table { width: 90%; border-collapse: collapse; line-height: 2; /* 行距 */ } th, td { font-size: 16px; /* 字體大小 */ } </style> | 指令 | 解釋 | | --------------- | ------------------------------------------------- | | JMPEQ R=R0, F | 若 Register R 等於 Register R0 將程式跳到 Flag F | | HALT | 停止 | | LOAD R, [S] | 將 Register S 中的值作為記憶體位址並將其中的值填入 Register R<br>e.g. S 中值為 65 就將記憶體 65 中的值填入 R | | STORE R, [S] | 將 Register S 中的值作為記憶體位址並將 Register R 的值填入其中<br>e.g. S 中值為 65 就將 R 中的值填入記憶體 65 | | JMPLE R<=R0, XY | 若 Register R 小於等於 Register R0 將程式跳到 Flag F | | JMP F | 將程式跳到 Flag F | | DB F | Define Byte | ---- ### 三種不同的定址方法 - <font size="6">Immediate Addressing</font> - <font size="6">load R1, 0x64</font> - <font size="6">Direct Addressing</font> - <font size="6">load R1, [0x64]</font> - <font size="6">Indirect Addressing</font> - <font size="6">load R1, [R5]</font> --- ## BRANCHING <div style="width: 400px; float: left; margin:0px 20px 0px 50px;"> <font size="6">在 C 語言中:</font> <pre style="font-size: 20px;"> <code>if(...) do something else do another thing </code> </pre> </div> <div style="width: 400px; float: left; margin: 0px;"> <font size="6">組合語言:</font> <pre style="font-size: 20px;"> <code>main: LOAD R0, [0x60] LOAD R1, [0x61] JMPEQ R1=R0, equal JMP noteq equal: LOAD R2, [0x62] ADDI R3, R1, R2 STORE R3, [0x70] HALT noteq: LOAD R2, [0x63] ADDI R3, R1, R2 STORE R3, [0x70] HALT </code> </pre> </div> --- ## LOOPING <div style="width: 400px; float: left; margin:0px 20px 0px 50px;"> <font size="6">在 C 語言中:</font> <pre style="font-size: 20px;"> <code>for(int a = 0; a < 10; a++) do something </code> </pre> </div> <div style="width: 400px; float: left; margin: 0px;"> <font size="6">組合語言:</font> <pre style="font-size: 20px;"> <code>main: LOAD R0, [0x60] LOAD R1, 1 LOAD R2, 1 JMP loop loop: ADDI R1, R1, R2 JMPLE R1<=R0, loop JMP out out: HALT </code> </pre> </div> --- ## 作業網站 作業做完請上傳到 http://140.121.197.13/tutorial 並且注意上傳時間限制、檔名、其他規範 上課時提前做完可以直接給助教 demo 登記 就不需要上傳 demo 過的部分 ---- ## Question 1 <font size=5> Write a program to compute the <div class="command">XOR</div> value of address <div class="command">0x6C</div>, <div class="command">0x6D</div>, <br>and store the results in address <div class="command">0x6E</div> </font> ---- ## Question 2 <font size=5>Write a program to swap the values of memory location of <div class="command">0xA0</div> and <div class="command">0xB0</div>. </font> ---- ## Question 3 <font size=5>Fill in the values <div class="command">0x1</div>, <div class="command">0x2</div>, <div class="command">0x3</div>, <div class="command">0x4</div>, <div class="command">0x5</div>, <div class="command">0x6</div>, <div class="command">0x7</div>, <div class="command">0x8</div>, <div class="command">0x9</div>, <div class="command">0xA</div> into the memory location starting from <div class="command">0x50</div>. Write a assembly program and add the values within the memory locations <div class="command">0x50</div> to <div class="command">0x59</div> and store it into memory location <div class="command">0x40</div>. </font> ---- ## Question 4 <font size=5> Write a program to add the values of 1 to x, <br>where 1 ≤ x ≤ 20. (x can be stored in some register) </font> ---- ## Question 5 <font size=5> For the program below, instead of adding <br>the value of memory address <div class="command">0x6C</div> and <div class="command">0x6D</div>, (<div class="command">0x6C</div> + <div class="command">0x6D</div>),<br> change the program with the available instructions to do subtraction,<br> i.e., <div class="command">0x6C</div> - <div class="command">0x6D</div>. </font> ``` load R5, [0x6C]; Load the value of memory address 0x6C into R5 load R6, [0x6D]; Load the value of memory address 0x6D into R6 addi R0, R5, R6; Adds the value of R5 and R6 and store i t in R0 store R0, [0x6E]; Stores the value of R0 to memory address 0x6E halt ``` ---- ## Question 6(Hard) <font size=5> Write a program to perform bubble sort<br> within the memory locations of <div class="command">0xC0</div> to <div class="command">0xCF</div>.<br> (Requires using <div class="command">load R, [S]</div> and <div class="command">store R, [S]</div>) </font> <font size = 5>hint : [bubble sort](https://www.youtube.com/watch?v=Dv4qLJcxus8)</font>

    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