資工期中超渡團
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 微算機與組合語言 Microprocessor & Assembly language # Chapter 1 ## Computers Evolution - Mainframe-> minicomputers-> workstation-> Microcomputers -> mobile devices - Microcomputers - Apple-> Apple II-> IBM PC/XT-> IBM PC/AT-> IBM Compatible PC(PC)-> notebook & tablet PC -> PDA & cell phone ## CPU Evolution - Microprocessors (Intel) - 4004 ->8008-> 8080-> 8085-> 8086-> 8088-> 80286-> 80386-> 80486-> Pentium-> Pentium Pro-> Pentium II-> Pentium III-> Pentium IV - 4bits-> 8bits-> 16bits-> 32bits-> 64bits - Single core - Due Core (2) - Quad Core (4) - Hexa Core (6) - Octa Core (8) - Deca Core (10) - Dodeca Core (12) - Hexadeca Core (16) ![](https://i.imgur.com/fv9JJN7.png) ![](https://i.imgur.com/vE6IP8w.png) ![](https://i.imgur.com/WKinqd3.png) ![](https://i.imgur.com/ISI2AA3.png) ## Computers Evolution - Classification of microprocessors - Reprogrammable microprocessor - For general purpose microcomputer - Embedded microprocessor - For special purpose microcomputer - In general, implemented as a single chip - 8051, ARM ![](https://i.imgur.com/KRZZgyy.png) ## General Architecture - Microcomputer & microprocessor - IC (integrated circuit) - SSI, MSI, LSI, VLSI, ULSI, ... ![](https://i.imgur.com/HkY4iZ8.png) ![](https://i.imgur.com/64CrtR8.png) - 8086/8088 Family - Upward compatible - 80286 can execute 8088/8086 code - Memory management, protection, and multitasking ![](https://i.imgur.com/ruK1AlI.png) ![](https://i.imgur.com/wZnVq2k.png) ![](https://i.imgur.com/RLUVGlc.png) # Chapter 2 ## Internal architecture ### BIU (Bus Interface Unit) * Performing external bus operations * e.g. Fetch Instruction and data ### EU (Execution Unit) * perform operations ![](https://i.imgur.com/WcF2c3t.jpg) ### BIU prefetch instructions into instruction queue ### Register * segment * pointer * data ### ALU (Arithmetic logic unit) ### Flags * status * control ![](https://i.imgur.com/oNV2KYy.jpg) ## Register 32 bits: 80286 above ### Instruction Pointer ### Segment Register * CS (Code Segment) + IP (Instruction Pointer) * DS (Data Segment) + SI (Source Index) * ES (Extra Segment) + DI (Destination Index) * SS (Stack Segment) + SP (Stack Pointer)/BP (Base Pointer) ### Data Register * AX (Accumulator) * BX (Base) * CX (Counter) * DX (Data) ### Pointer & Index * BP (Base Pointer) * SP (Stack Pointer) * SI (Source Index) * DI (Destination Index) ### Status Register #### Status flags ##### CF (Carry Flag): * is set if there is a carry-out or a borrow-in for the most significant bit of the result * 最高位借進位時,CF=1 ##### PF (Parity Flag): * is set if the result produced by the instruction has even parity. * If the parity is odd, PF reset * 結果有偶數個位元=1時,PF=1 ##### AF (Auxiliary Flag): * Is set if there is a carry-out from the low nibble into the high nibble. Otherwise AF is reset. * 將暫存器長度切為一半 (nibble),若低 nibble 有進位至高 nibble,AF=1 * 比如 16-bit register,從第7位進位到第8位時(最低位為第0位),AF=1 ##### ZF (Zero Flag): * Is set if the result produced by an instruction is zero. Otherwise, ZF is reset * 結果是0,ZF=1 ##### SF (Signed Flag): * The MSB (Most Significant Bit) of the result is copied into SF. * Is set if the result is a negative, reset if it is positive * 結果最高位(負數)=1,SF=1 ##### OF (Overload Flag): * Is set if the signed result out of range, otherwise remains reset * 溢位時,OF=1 #### Control flags ##### TF (Trap Flag): * If TF is set, 8088 goes into the single-step mode. * Very useful for debugging programs * 開下去會逐步執行,所以常拿來除錯 ##### DF (Direction Flag): * Determine the direction in which string operations will occur. When set, the string instruction automatically decrements the address; * if reset the string address will be incremented * 如果 DF=1,將由高位元讀到低位元 ##### IF (Interrupt Flag): * For the 8088 to recognize maskable interrupt requests at its interrupt (INT) input, the IF must be set * When IF is reset, requests at INT are ignored and the maskable interrupt interface is disabled. * Maskable interrupt v.s. Non-maskable interrupt (highest priority of interrupt) # Chapter 3 ## Native language is machine language ### A program written in language is often called machine code * encoded using 0, 1 ### An instruction can be divided into two parts (Operation code) * operation code (opcode) * operands ### Each opcode is assigned a unique letter combination called a menmonic * MOV AX, BX * move bx register to ax register ## Advantages of assembly program than high-level program ### Small code size * Useful for limited memory space ### Short execution time * Useful for real-time app. or time-sensitive app. ### Low level control * Device service routines ## Addressing mode Access different type of operands, the 8088 is provided with various addressing modes ### Specify an operand * register addressing mode * immediate addressing mode * memory addressing mode (direct, register indirect, based, indexed, based-indexed) ### Register operand addressing mode * 所指定的就是 register 裡面的內容 * MOV AX, BX ### Immediate operand addressing mode * 後面那個就是值,帶進去前面的暫存器就好 * MOV AX, 12h ### Memory operand addressing mode Physical address (PA) is computed from a segment base address (SBA) and effective address (EA) PA = SBA : EA PA = Segment base : Base + Index + Displacement 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 #### Direct addressing mode * MOV CX, [1234h] * Physical address(PA) = {CS, DS, SS, ES} * 16 + {Direct address} #### Register indirect addressing mode * MOV AX, [SI] * PA = {CS, DS, SS, ES} * 16 + {BX, BP, SI, DI} #### Based addressing mode * MOV [BX]+1234H, AL * PA = {CS, DS, SS, ES} * 16 + {BX, BP} + {8/16-bit displacement} #### Indexed addressing mode * MOV AL, [SI]+1234H * PA = {CS, DS, SS, ES} * 16 + {SI, DI} + {8/16-bit displacement} #### Based-Indexed addressing mode * MOV AH, [BX][SI]+1234H * PA = {CS, DS, SS, ES} * 16 + {BX, BP} + {SI, DI} + {8/16-bit displacement} # Chapter5 D:Destination 目的地 S:Source 來源 Q:Quotient 商 R:Remainder 餘數 ## Data transfer instructions ### MOV - 賦值 - MOV D, S - S -> D ``` MOV AX, 1234H ``` ### XCHG - 交換 - XCHG D, S - D <-> S ``` MOV AX, 1234H MOV BX, 4567H XCHG AX, BX ``` ### XLAT - 查表轉換 - AL+BX+DX -> AL - 會查 AL+BX+DX 然後放到 AL ``` MOV BX, 1000H MOV DX, 1000H MOV [DX+BX+0BH], 42H MOV AL, 0BH XLAT ;AL = 42H ``` ### LEA - Load register with effective address - LEA Reg16, EA - EA -> Reg16 - 跟 C++ 取址符號 & 做的事情一樣 ``` MOV BX, 100H MOV BX+100H, 1234H MOV AX, BX+100H ;AX = 1234H LEA AX, BX+100H ;AX = 200H MOV AX, [200H] ;AX = 1234H ``` ### LDS - Load register and data segment register - LDS Reg16, EA - EA -> Reg16 - EA + 2 -> DS - MOV + 更改DS ``` MOV BX, 100H MOV BX+100H, 1234H MOV BX+102H, 5678H LDS AX, BX+100H ;AX = 1234H, DS = 5678H ``` ### LES - Load register and extra segment register - LES Reg16, EA - EA -> Reg16 - EA + 2 -> ES - MOV + 更改ES ``` MOV BX, 100H MOV BX+100H, 1234H MOV BX+102H, 5678H LES AX, BX+100H ;AX = 1234H, ES = 5678H ``` ## Arithmetic instructions ### Addition instruction #### ADD * addition * ADD D, S * S + D -> D * Carry -> CF * 加完後的值放在靠近 ADD 的register ``` MOV AX, 1234H MOV BX, 4567H ADD AX, BX ``` #### ADC * add with carry flag * ADC D, S * S + D + CF -> D * Carry -> CF ``` MOV DL, 0 MOV AL, 0FFH ADD AL, 0FFH ADC DL, 0 ;DL = 1H ``` #### INC * 加一 * INC D * D + 1 -> D ``` MOV AX, 1H INC AX ``` #### AAA ![](https://i.imgur.com/wXEx50T.png =100x100) - ASCII adjust for addition - 加完後變成BCD ``` MOV AL, '8' ADD AL, '9' AAA ;AX = 0107H ``` #### DAA - decimal adjust for addition - 如果 AL 的低 4 位大於 9 或 AF=1,則 AL+06H,並將 AF 置 1; 如果 AL 的高 4 位大於 9 或 CF=1,則 AL+60H,且將 CF 置 1。 如果兩個都不滿足,則將AF,CF清零。 - 16進位加法變成10進位 ``` MOV AL, 37H MOV BL, 35H ADD AL, BL DAA ;AL = 72H ``` ### Subtraction instructions #### SUB * subtract * 減完後的值放在靠近 ADD 的register * SUB D, S * D - S -> D * Borrow -> CF ``` MOV AX, 4567H MOV BX, 1234H SUB AX, BX ;AX = 3333H ``` #### SBB * subtract with borrow * SBB D, S * D - S - CF -> D ``` MOV AX, 43H MOV BX, 49H SUB AX, BX ;AX = FFFAH, CF=1 SBB AX, 9H ;AX = FFF0H ``` #### DEC * 減一 * DEC D * D - 1 -> D ``` MOV AX, 43H DEC AX ``` #### AAS - ASCII adjust for subtraction - 把BCD拿來減 ``` MOV AX, 0103H MOV BX, 4H SUB AL, BL ;AL = FFH AAS ;AX = 0009H ``` #### DAS - decimal adjust for subtraction - 如果 AL 的低四位大於 9 或 AF=1,則 AL-06H,並將 AF 置 1; 如果 AL 的高四位大於 9 或 CF=1,則 AL-60H,並將 CF 置 1; 如果兩個都不滿足,則將 AF , CF 清零。 - 16進位減法變成10進位 ``` MOV AX, 32H MOV BX, 25H SUB AL, BL ;AL = 0DH DAS ;AL = 07H ``` #### NEG * 取二補數 * NEG D * 0 - D -> D * 1 -> CF ``` MOV AX, 003AH NEG AX ;AX = FFC6H ``` ### Multiplication and Division instrucion #### MUL - Multiply ( unsigned ) - MUL S - AL * S(8bits) -> AX - AX * S(16bits) -> DX,AX ``` MOV AX, 1234H MOV BX, 1234H MUL BX ;DX,AX = 014BH,5A90H ``` #### DIV - Division ( unsigned ) - DIV S - AX / S(8bits) - Q -> AL - R -> AH - DX:AX / S(16bits) - Q -> AX - R -> DX ``` MOV AX, 1234H MOV BX, 3H DIV BX ;DX:AX = 0001H:0611H ``` #### IMUL - Integer multiply ( signed ) - IMUL S - AL * S(8bits) -> AX - AX * S(16bits) -> DX,AX ## Logic instructions ### AND - Logical AND - AND D, S ### OR - Logical OR - OR D, S ### XOR - Logical XOR - XOR D, S ### NOT - Logical NOT - NOT D ## Shift instructions ### SAR/SAL - Shift arithmetic left/right - SAR/SAL D, Count - 最高位bit不動,其他的往左/右移 Count bits - 會將從L(SAL)/R(SAR)數過來第 Count 的 Bit 放到 CF - SAR的空出的bits會補上最高位的bit,SAL會補0 ``` MOV AX, 891AH MOV CL, 2H SAR AX, CL ;AX = E246, CF = 1 ``` ### SHL/SHR - Shift logical left/right - SHR/SHL D, Count - 往左/右移 Count bits - 會將從L(SHL)/R(SHR)數過來第 Count 的 Bit 放到 CF - SHR/SHL空出來的bits會補0 ``` MOV AX, 091AH MOV CL, 2H SHR AX, CL ;AX = 0246, CF = 1 ``` ## Rotate instructions ### ROL/ROR - 與SHL/SHR差別於超出去的bits會補到另一端 ### RCL/RCR - 與ROL/ROR差別於移位方向的前端多一格CF ###### tags:`CSnote`

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