莫寶琳
    • 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
    # Lab02 Addressing Mode ## (1) What is Addressing Mode? Link:[IS for PIC18F4520](http://technology.niagarac.on.ca/staff/mboldin/18F_Instruction_Set/) ## (2) PIC18F4520 Adressing Mode #### <font size=4>No Operation - NOP #### Inherent Addressing (Implied Addressing) - SLEEP、RESET、DAW #### Literal Addressing (Immediate Addressing) - MOVLW、ADDLW、SUBLW、ANDLW、GOTO、CALL...​​ #### Direct Addressing (Absolute Addressing)​ #### <font color=red>Indirect Addressing</font> #### Bit Addressing #### Relative addressing --- ### No Operation - NOP ![](https://i.imgur.com/2tjsApd.png) Sample code: ```as= #INCLUDE <p18f4520.inc> CONFIG OSC = INTIO67 CONFIG WDT = OFF org 0x10 ;PC = 0x10 start: nop nop nop nop nop end ``` - PC += 2 - "wasting" 1 clock cycle - delay loop ### Inherent Addressing - SLEEP、RESET、DAW - SLEEP ![](https://i.imgur.com/4Lu5Qv4.png) - RESET ![](https://i.imgur.com/rEGFAgT.png) - DAW ![](https://i.imgur.com/FsTofJf.png) - BCD addition adjustment ![](https://i.imgur.com/67vcebB.png) ### Literal Addressing - 8-bits literal MOVLW、ADDLW、SUBLW、ANDLW - 20-bits literal *GOTO... Sample code: ```as= #INCLUDE <p18f4520.inc> CONFIG OSC = INTIO67 CONFIG WDT = OFF org 0x10 ;PC = 0x10 start: MOVLW 0x05 end ``` ![](https://i.imgur.com/VrxLUEa.png) ### Direct Addressing - Data Memory MAP ![](https://i.imgur.com/P9zqJMK.png) <font color=red>12-bits memory address, higher 4 bits for bank select. ==> 將整塊4096Bytes的記憶體區分成16個小區(bank0~bank15)</font> - Some data movement instructions on file register - *Access Bank - Access RAM ( or GPRs) (0x000 ~ 0x07F and 0xF80 ~ 0xFFF) - Bank Select (higher address) (0x000 ~ 0xFFF) <font color=red>(*) 因為 data movement 的 file register 欄位只有 8 個 bits,所以 Access Bank 方式只能存取 256 個 bytes 的記憶體空間(0x000 ~ 0x07F 和 0xF80 ~ 0xFFF)。 因此若要存取整個 4096-bytes 大小的記憶體空間,要使用 Bank Select 的方式存取。</font> - MOVWF ![](https://i.imgur.com/Eo46jce.png) - MOVLB (Use MOVLB to select bank) ![](https://i.imgur.com/V34Yq2o.png) - MOVFF ![](https://i.imgur.com/D90e2vm.png) <font color = red>MOVFF 是一個很特別的指令,他的指令格式是給你兩個 12-bits 的 file register 欄位去填,所以在整個 4096-bytes 大小的記憶體裡,想去哪就去哪,不需要在乎bank這件事,也就是這個指令可以隨意在 4096-bytes 大小的記憶體空間裡存取。</font> Sample code: Access Bank ```as= #INCLUDE <p18f4520.inc> CONFIG OSC = INTIO67 CONFIG WDT = OFF org 0x10 ;PC = 0x10 start: MOVLW 0x99 ; WREG = 0x99 MOVWF 0x10 ; [0x010] = 0x99 end ``` ![](https://i.imgur.com/PauXtZJ.png) Sample code: Bank Select ```as= #INCLUDE <p18f4520.inc> CONFIG OSC = INTIO67 CONFIG WDT = OFF org 0x10 ;PC = 0x10 start: MOVLW 0x99 ; WREG = 0x99 MOVLB 0x4 ; BSR = 4 MOVWF 0x10, 1 ; use BSR select bank ; [0x410] = 0x99 end ``` ![](https://i.imgur.com/HkJwJ3u.png) Sample code: MOVFF ```as= #INCLUDE <p18f4520.inc> CONFIG OSC = INTIO67 CONFIG WDT = OFF org 0x10 ;PC = 0x10 start: MOVLW 0x99 ; WREG = 0x99 MOVLB 0x4 ; BSR = 4 MOVWF 0x10, 1 ; use BSR select bank ; [0x410] = 0x99 MOVFF 0x410, 0x420 ; [0x420] = 0x99 end ``` ![](https://i.imgur.com/h21pR1v.png) ### Indirect Addressing #### Three SFRs call FSRx (x for 0~2) - FSR0、FSR1、FSR2 - 16bits (FSRxH : FSRxL) to cover all data memory address - they are pointer - LFSR ( let FSRx point to memory address k ) - ![](https://i.imgur.com/DqRMH9c.png) #### Some SFRs related to pointer FSRx (x for 0~2) - INDFx:指針不變,對指向的記憶體位置進行操作 - PLUSWx:指針 + WREG = 新的記憶體位置後,對指向的記憶體位置進行操作 - POSTINCx:對指向的記憶體位置進行操作後,指針 + 1 - POSTDECx:對指向的記憶體位置進行操作後,指針 - 1 - PREINCx:指針 + 1 後,對指向的記憶體位置進行操作 Sample code: ```as= #INCLUDE <p18f4520.inc> CONFIG OSC = INTIO67 CONFIG WDT = OFF org 0x00 ;PC = 0x00 setup1: LFSR 0, 0x000 ; FSR0 point to 0x000 LFSR 1, 0x010 ; FSR1 point to 0x010 LFSR 2, 0x020 ; FSR2 point to 0x020 MOVLW 0x10 ; WREG = 0x10 start: INCF POSTINC0 ; [0x000] += 1; FSR0 point to 0x001 INCF PREINC1 ; FSR1 point to 0x011 ;[0x011] += 1 INCF POSTDEC2 ; [0x020] += 1 ; FSR2 point to 0x01F INCF INDF2 ; [0x01F] += 1 ; ; FSR2 point to 0x01F(unchanged) INCF PLUSW2 ; [0x01F+0x10] += 1 ; FSR2 point to 0x01F(unchanged) end ``` ### Bit Addressing - BSF、BCF、BTFSC、BTFSS - Set or clear specific bit file register Sample code: ```as= #INCLUDE <p18f4520.inc> CONFIG OSC = INTIO67 CONFIG WDT = OFF org 0x10 ;PC = 0x10 start: BSF 0x000, 1 end ``` ![](https://i.imgur.com/NuGWFZr.png) ### Relative Addressing - BC、BN、BNC、BNN、BNZ(branch if not zero) ... - for all the "Branch" instruction to addressing - relative address to PC value (branch的下一行) - offset is word address(for PIC18F4520 1 word = 2Bytes) - if branch: PC = PC + 2 + n * 2 (2's complement) if not branch: PC = PC + 2 ![](https://i.imgur.com/rcmUnvF.png) - Example: ![](https://i.imgur.com/YMImsIb.png) </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