YuminChiang
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    --- tags : 微算機與組合語言 --- ###### 國立臺北大學資工系江宥旻 Assembly Language Programming === Software:The microcomputer program --- Hierarchy of Programming Language + High Level Language ```c int a = 0, b = 0; a = 2; b = 5; a = a * a + 3 * b + 6; printf("The Integer: %d", a); ``` + Low Level Language (Assembly Language) ```asm MOV ax, 2 MOV cx, ax MOV bx, 5 mul ax, cx add ax, bx ``` + Machine Language ```ml 1001000100011110 0111001010010101 1100110101110101 1110001111011010 0101110101010101 ``` + CPU Execution + Fetch Instruction + Decoding + Retrieve Data + Execution + Write Back Native language is machine language + A program written in machine language is often called machine code + Is encoded using 0, 1 + An instruction can be divided into two parts + Operation code (opcode)運算子 + Operands運算元 + Each opcode is assigned a unique letter combination called a `mnemonic(助憶碼)` + MOV AX, BX + Move bx register to ax register + Physically cpu copies the value of BX into AX + BX is source operand and AX is destination operand --- Simple program that can be translated into machine code using MASM 6.0 MASM (將組合語言轉成機器碼) + Macro Assembler + Translating mnemonic code into machine code (object code) ```asm ;***************** ;* SIMPLE.ASM ;***************** .MODEL small .DATA CR EQU 0DH ;EQU等於用來定義常數DB define byte LF EQU 0AH ONE DB 01h MESSAGE DB 'smile’, CR, LF, '$' .CODE start: MOV ax, @data ;DS 移到資料區開始地 MOV ds, ax MOV ah, 02h MOV dl, ONE int 21h MOV ah,09h MOV dx,OFFSET MESSAGE ;DX 移到字串的位址 int 21h MOV ah,4ch int 21h .STACK END start ``` :::info 一個程式會有三個區 + .DATA 資料區 + .CODE 程式區 + .STACK 堆疊區 ::: > 組譯程式把組合語言轉換成機器碼 > OD、OA(CR、LF):carriage return and line feed (游標移到最前並換行) ![app-os.png](https://i.imgur.com/4q3Etmx.png =400x) [INT 21H 指令說明及使用方法](https://www.796t.com/content/1548310330.html) int 21h是一種中斷程式(interrupt)是OS提供給APP使用的,能夠讓APP進到OS,讓OS做APP想做的事。 Advantages of assembly program than high-level program + Small code size `程式小` + Useful for limited memory space + Short execution time `執行快` + Useful for real-time application or time-sensitive application + Low level control `I/O控制,高階語言很難做到` + Device service routines OS的程式 + C:95% + 組合語言:5% Assembly language program development on the PC --- ![PC-asm](https://i.imgur.com/TeXNaz6.jpg =300x) The Instruction set --- `117 basic instructions` for the 8088/8086 + Data transfer + Mov, push, pop, XCHG(exchange), in, out, ... > XCHG:register直接交換,不用多設變數 + Arithmetic + Add, adc, inc, sub, sbb, dec, cmp, ... > inc:++,sbb:-- + Logic + And, or, not, shift, rotate, test, xor, ... + String manipulation + Rep, movs, cmps, ... > Rep:重複 + Control transfer + Call, ret, jmp, conditional jump, loop, conditional loop, int, ... + Processor control + Clc, cmc, stc, cli, (set and reset flag), ... The MOV instruction --- ### MOV D, S > D:(Destination)目的,S:(Source)來源。來源的值`copy`一份到目的 ![D-S](https://i.imgur.com/XZycMUG.jpg =400x) + Memory + `[]`:記憶體,內部的值很像arr[index]的概念。 + Accumulator (AX) + Register + Seg-reg (區段暫存器) + Reg16 (DX) + Immediate (立即值) Example: 1. MOV AL, '0' + AL:register + '0':immediate 2. MOV [400], AL + []:memory + AL:register 3. MOV BL, [400] + BL:register + []:memory 4. MOV [402], 02 + []:memory + 02:immediate 5. ADD AL, BL + AL <- AL + BL 6. SUB AL, CL + AL <- AL - CL ![mov](https://i.imgur.com/9os1asN.jpg =300x)![mov2](https://i.imgur.com/VmGPgu2.jpg =300x) > 把CS的值複製一份到DX Addressing mode 定址模式 --- CPU找到資料的方式,稱作定址模式。 Access different type of operands, the 8088 is provided with various addressing modes. + `Register` addressing mode + `Immediate` addressing mode + `Memory` addressing mode + Direct + Register indirect + Based + Indexed + Based-Indexed ![addressing-mode](https://i.imgur.com/ff207Q5.jpg =300x) --- ### Register operand addressing mode ``` MOV AX, BX ``` ![ram](https://i.imgur.com/VkMyoXo.jpg =300x) ![ram2](https://i.imgur.com/zd7SxKt.jpg) > Data在register裡,不用到memory裡拿,也就是說不用去算實體位址。 --- ### Immediate operand addressing mode ``` MOV AL, 15H ``` ![iam](https://i.imgur.com/9jcsmUs.jpg =300x) ![iam2](https://i.imgur.com/tln6KYX.jpg) > Data在指令中裡,可立即拿到,不在register也不在memory,也就是因為不在memory裡,所以就不用去算實體位址。 --- ### Memory operand addressing mode `Physical address (PA)` is computed from a segment base address (SBA) and an effective address (EA) > 資料在memory裡,所以要去算**實體位址** Five memory operand addressing modes + Displacement:Direct addressing mode + BX, BP, SI, DI:Register indirect + BX or BP + displacement:Based + SI or DI + displacement:Indexed + BX, BP + SI, DI + displacement:Based-Indexed > Based和Indexed,很像,差別在用的register不同 ![mam](https://i.imgur.com/Bxw3kaq.jpg =300x) **Direct Addressing Mode** ``` MOV CX, [1234H] ``` ![dam](https://i.imgur.com/Gu9PTfm.jpg =500x) ![dam2](https://i.imgur.com/ZBEe1nO.jpg =400x) > PA = SBA * 16 + EA > 為何是用DS(Data segment)算呢?因為資料在資料區,所以是用DS算。 **Register Inderict Addressing Mode** ``` MOV AX, [SI] ``` ![riam](https://i.imgur.com/McGEVyU.jpg) ![riam2](https://i.imgur.com/BuwglnU.jpg =400x) **Based Addressing Mode** > 常用在一維陣列 ``` MOV [BX] + 1234H, AL ``` ![bam](https://i.imgur.com/HVhv6fJ.jpg) ![bam2](https://i.imgur.com/f9bRyto.jpg =400x) **Indexed Addressing Mode** ``` MOV AL, [SI] + 1234H ``` ![miam](https://i.imgur.com/CLivgvR.jpg) ![miam2](https://i.imgur.com/gZLGyGy.png =400x) **Based-Indexed Addressing Mode** > 常用在二維陣列 ``` MOV AH, [BX][SI] + 1234H ``` ![biam](https://i.imgur.com/aPniU4w.jpg) ![biam2](https://i.imgur.com/3StVZKX.jpg =400x) 參考資料 + Barry B. Bery, “The Intel Microprocessors,” 8th Edition, 2009, Prentice Hall. + Walter A. Triebel, Avtar Singh, “The 8088 and 8086 Microprocessors – Programming, Interfacing, Software, Hardware, and Applications,” 4th Edition, 2003, Prentice Hall. + 國立臺北大學資工系張玉山教授ppt

    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
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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