This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Assume the executable file of the program example.c is called example.exe. (a) Which program handles the statement "#include <stdio.h>" in file example.c?(b) Which program handles the statement at line 2 in file example.c to generate corresponding machine code in example.exe?(哪個program有line 2的statement可以產生相應的機器碼(也是目的碼:object code)於可執行檔example.exe呢?)
How OS Execute A Program?OS會先在RAM配置一塊給Program用的記憶體,再將.exe檔由硬碟仔速到專屬記憶體program counter(城市指位器)指向該記憶體中的Machine code起始位置程式開始執行 CPU fetches a machine code, (may need decoding), execute it and move PC so that it PC can point to the next instruction.Unless Jump happens, PC points to other address where the machine code put. Fetch -> Decode -> Execute -> Increment PC ——^——循環——————————————————| 編譯器Compiler的工作例子:Object Code 程式語言(Source Code)Register <- [b] a=b+cRegister <- [c]選擇&執行加法電路Register -> [a] 把原始碼重新編成、翻譯為machine code(object code, binary code)。因為CPU 無法處理有語意的指令,所以如上面的例子,意思是把 b 和 c 相加以後,以此結果賦予 a 變數的值,編譯器所產生的機械碼可能是把 [b] 數值搬移(move)到 暫存器,接著把 [c] 數值搬移到 CPU 的另一個暫存器,接著如上圖地,輸出加法運算的機械碼(設定 CPU 周圍的針腳以選用加法電路),若干 clock 以後,某個暫存器中的值變成方才兩個暫存器相加的值,接著下一行,另一個搬移的機械碼又把結果搬移到記憶體的 [a] 位置。