jacklee20499
    • 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: `程式揭秘:從C/C++程式碼探索電腦系統的運作原理` :::info **探究電腦系統內部結構和工作原理,是為了能夠準確地把握代碼指令的傳遞和處理流程,找出限制和降低程序運行效率的關鍵點所在,從而讓工程師能夠跟隨電腦一同思考,並寫出高效、可靠的程式碼。** ::: 1.1 電腦系統初探 --- :::success 通常一個用戶與電腦之間的交流需要經過幾個步驟 用戶->應用軟體->作業系統->硬體設備 ::: ![圖1-1 用戶與電腦的交互](https://i.imgur.com/8sYpOMN.png) 1.1.2 CPU很好很強大 --- :::success 范紐曼型架構(英語:Von Neumann architecture),也稱馮·紐曼模型(Von Neumann model)或普林斯頓架構(Princeton architecture),是一種將程式指令記憶體和資料記憶體合併在一起的電腦設計概念架構。 ::: ![圖1-2 電腦組成結構示意圖](https://i.imgur.com/SFtIuod.png) ## 范紐曼瓶頸 :::success 將CPU與記憶體分開並非十全十美,反而會導致所謂的范紐曼瓶頸(von Neumann bottleneck):在CPU與記憶體之間的流量(資料傳輸率)與記憶體的容量相比起來相當小,在現代電腦中,流量與CPU的工作效率相比之下非常小,在某些情況下(當CPU需要在巨大的資料上執行一些簡單指令時),資料流量就成了整體效率非常嚴重的限制。CPU將會在資料輸入或輸出記憶體時閒置。由於CPU速度遠大於記憶體讀寫速率,因此瓶頸問題越來越嚴重。 為了提高CPU的利用率,從而提升計算機的整體效率,人們設計了**緩存(Catche)** 這個結構。緩存是一個特殊的高速內存,緩存通常是使用SRAM製成的。當CPU處理資料時,它會先到Cache中去尋找,如果資料因之前的操作已經讀取而被暫存其中,就不需要再從隨機存取記憶體(Main memory)中讀取資料——由於CPU的執行速度一般比主記憶體的讀取速度快,主記憶體儲器周期(存取主記憶體儲器所需要的時間)為數個時鐘周期。因此若要存取主記憶體的話,就必須等待數個CPU周期從而造成浪費。 ::: ## CPU如何運作 :::success 馮·紐曼CPU的運作原理可分為四個階段:提取、解碼、執行和寫回。 - 提取:控制器從RAM提取指令。 - 解碼:控制單元對指令進行解碼,並根據解碼的結果將必要的數據從RAM中轉移到ALU中。 - 執行:控制器指導ALU執行必要的邏輯或算數運算。 - 寫回:計算結果儲存到RAM中。 ::: ![圖1-3 CPU執行指令過程](https://i.imgur.com/afqg3j9.png) # 1.21 如何讓電腦理解你 :::danger 機器語言 因為其指令格式是以0和1組合而成,不需翻譯過程,可以直接執行,所以速度最快。 不同的處理機,使用不同的機器語言,所以其可攜性差。 只有0、1兩種符號,指令敘述的編寫必須強記其代碼,不僅難學、難懂、遇有錯誤亦不易察覺。 ::: :::warning 組合語言 由於機器語言在使用上的不便,因此工程師們便從機器語言中找出規則,而以英文字、數字符號來重組機器語言,使成為更易理解的語言,這種語言便稱為組合語言(Assembly language)。這些具有特定功能的符號指令稱為助憶碼(Mnemonic code),例如:ADD AX,BX代表「將AX及BX的內容相加」、MOV CX,0代表「將0搬移至CX內部」,這些指令比起機器語言來說可算是比較容易了解多了;但是以組合語言撰寫好的程式無法直接執行,必須經過組譯器(Assembler)翻譯成機器語言才能執行。 ::: :::success 高階語言 從1950年代開始,許多大學或電腦公司便著手設計如何讓電腦語言更接近人類語言、更容易撰寫及閱讀,讓即使不懂電腦硬體結構的人,也可以設計程式解決問題;因為這些程式語言的語法接近人類語言,我們稱之為高階語言(High level language)。以高階語言所設計的程式,在執行時必須先以編譯器(Compiler)、或直譯器(Interpreter)翻譯成機器語言,才能被電腦硬體執行。 ::: ![圖1-4 電腦語言](https://i.imgur.com/iPuUyD5.png) # 現今流行的語言 :::success 書中提到第一個高階語言為FORTRAN,其他耳熟能詳的還有Basic, Pascal, C, C++, Java等,但現在流行的語言已經跟書中提到的有落差了,在這邊補充一下資訊。 ::: ![補充1 最受歡迎語言排行](https://i.imgur.com/Qg5lbpP.png) :::danger :laughing: 2021薪資最高的語言排序,物以稀為貴 ::: ![補充 2薪資最高語言排行](https://i.imgur.com/nZDJq9g.png) # 1.2.3 程式開發流程 一般來說,使用高階語言進行程式設計的步驟如下: :::success 編輯(edit):平常你在寫的Source code 預處理(preprocess): - 將所有的「#define」刪除,並且展開所有的宏定義 - 處理所有的條件編譯指令,如:「#if」、「#ifdef」、「#elif」、「#else」、「endif」等。這些偽指令的引入使得程式設計師可以通過定義不同的宏來決定編譯程序對哪些代碼進行處理。預編譯程序將根據有關的文件,將那些不必要的代碼過濾掉。 - 處理「#include」預編譯指令,將被包含的文件插入到該預編譯指令的位置。 編譯(compile):其作用就是要變成電腦看得懂的二進位程式碼,compile舉例來說有常見的visual studio 系列, GCC等 連接(link):如果有動態函示庫連接的話,通常會以.dll等結尾 執行(run):開始執行程式,此時常會使用中斷點或log,gdb進行除錯的工作 ::: ![圖1-10 程式設計的步驟](https://i.imgur.com/Pvd6OCj.png) --- # 1.3.2 簡單說說C語言的特點 :::success C語言具有高效、靈活、功能豐富、表達力強和較高的可移植性等特點,在程式設計中備受青睞,成為最近25年使用最為廣泛的程式語言。目前,C語言編譯器普遍存在於各種不同的作業系統中,例如Microsoft Windows、macOS、Linux、Unix等。C語言的設計影響了眾多後來的程式語言,例如C++、Objective-C、Java、C#等。 ::: ![圖1-12 C語言的優點](https://i.imgur.com/FH3pbDo.png) --- # 1.4.1 C++的產生與發展 :::success 物件導向程式設計(英語:Object-oriented programming,縮寫:OOP)是種具有物件概念的程式設計典範,同時也是一種程式開發的抽象方針。它可能包含資料、特性、程式碼與方法。物件則指的是類別(class)的實例。它將物件作為程式的基本單元,將程式和資料封裝其中,以提高軟體的重用性、靈活性和擴充性,物件裡的程式可以存取及經常修改物件相關連的資料。在物件導向程式程式設計裡,電腦程式會被設計成彼此相關的物件。 ::: ![圖1-14 一個繼承圖](https://i.imgur.com/nqRdmOh.png) :::success 標準範本庫(STL,刷leetcode的好夥伴) 標準模板庫(英文:Standard Template Library,縮寫:STL),是一個C++ 軟體庫,大量影響了C++標準程式庫但並非是其的一部分。其中包含4個組件,分別為演算法、容器、函式、迭代器。 ::: 參考 --- https://zh.wikipedia.org/wiki/%E5%86%AF%C2%B7%E8%AF%BA%E4%BC%8A%E6%9B%BC%E7%BB%93%E6%9E%84 https://www.cool3c.com/article/166843 https://buzzorange.com/techorange/2021/08/24/php-programmer-payment-is-low/ https://kknews.cc/code/3ovv8y8.html https://zh.wikipedia.org/wiki/C%E8%AF%AD%E8%A8%80 http://163.25.97.1/~ansel/teaching/1002_ComputerProgramming/Ch01.pdf https://zh.wikipedia.org/wiki/%E6%A0%87%E5%87%86%E6%A8%A1%E6%9D%BF%E5%BA%93

    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