㈠ 指令,指令系統,程序,機器語言,匯編語言之間有什麼關系
指令,是CPU硬體設計時確定的、能夠完成特定操作的二進制格式的代碼。
指令系統,是某類CPU所能執行的所有指令的總和。
程序,是完成特定任務的多條指令構成的指令序列。
機器語言,是一種編程語言,它直接用二進制指令格式編寫或構造程序。
匯編語言,是一種編程語言,它將機器指令用易於理解和記憶畝茄宴的單詞或單詞縮寫符號來描述,用它寫出的程序需要翻譯成機器語言程序後才能運行,不納梁過翻譯非常非常簡單。迅銀
Borland出品的Delphi,有著閃電般的編譯速度,但是在界面控制項使用較多、工程項目較大的時候,編譯一個工程仍需要一段時間,打開龐大的Delphi IDE,也需要時間。其實,在一個工程開發結束,調試完成之後的Release編譯,完全可以用命令行來執行,因為Delphi的編譯器參數不像C++編譯器那樣復雜。
筆者把Delphi聯機手冊中關於命令行編譯(command-line compiler)的幾篇主題作了翻譯,希望對Delphi開發人員有幫助。
目錄
1. Command-line compiler
命令行編譯器
2. Command-line compiler options
命令行編譯器選項
3. Compiler directive options
編譯器指令選項
4. Compiler mode options
編譯模式選項
5. DCC32.CFG file
編譯器配置文件DCC32.CFG
6. Debug options
調試選項
7. Directory options
目錄選項
8. IDE command-line options
IDE命令行選項
9. Generated files
幾個IDE自動生成的文件介紹
Command-line compiler
命令行編譯器
Delphi's command-line compiler (dcc32.EXE) lets you invoke all the functions of the IDE compiler (DELPHI32.EXE) from the DOS command line (see IDE command-line options. Run the command-line compiler from the DOS prompt using the syntax:
Delphi』s命令行編譯器(dcc32.exe)允許你從DOS命令行方式(參照:IDE命令行選項)實現IDE編譯器(delphi32.exe)的所有功能。用DOS命令運行命令行編譯器語法如下:
dcc32 [options] filename [options]
dcc32 [選項] [文件名] [選項]
where options are zero or more parameters that provide information to the compiler and filename is the name of the source file to compile. If you type dcc32 alone, it displays a help screen of command-line options and syntax.
零或多個參數給編譯器提供信息,文件名指定需要編譯的源文件名。如果你單獨輸入dcc32,它會顯示一個關於命令行編譯的選項和語法的屏幕。
If filename does not have an extension, the command-line compiler assumes .dpr, then .pas, if no .dpr is found. If the file you're compiling to doesn't have an extension, you must append a period (.) to the end of the filename.
如果文件名沒有擴展名,命令行編譯器會查找擴展名為.dpr的同名文件,如果找不到,則查找擴展名為.pas的同名文件。如果你的源文件確實沒有擴展名,你需要在文件名的末尾添加(.)。
If the source text contained in filename is a program, the compiler creates an executable file named filename.EXE. If filename contains a library, the compiler creates a file named filename.DLL. If filename contains a package, the compiler creates a file named filename.BPL. If filename contains a unit, the compiler creates a unit file named filename.dcu.
如果指定的源文件是一個工程文件,編譯器會創建一個擴展名為.EXE的同名可執行文件。如果指定的源文件是一個庫文件,編譯器創建一個擴展名為.DLL的同名動態鏈接庫文件。如果指定的源文件是一個包文件,編譯器會創建一個擴展名為.BPL的同名包。如果指定的源文件是一個單元文件,編譯器會創建一個擴展名為.dcu的目標代碼文件。
You can specify a number of options for the command-line compiler. An option consists of a slash (/) or immediately followed by an option letter. In some cases, the option letter is followed by additional information, such as a number, a symbol, or a directory name. Options can be given in any order and can come before or after the file name.
你可以為命令行編譯器指定多個參數。一個參數包含一個破折號「-」(或「/」)和緊跟著的一個選項字元構成。通常情況下,選項字元後面會跟一些附加的信息,如一個數字、一個符號、一個目錄等。選項可以是任意順序並且可以在源文件名前面或後面。
Command-line compiler options
命令行編譯選項
The IDE lets you set various options through the menus; the command-line compiler gives you access to these options using the slash (/) delimiter. You can also precede options with a hyphen (-) instead of a slash (/), but those options that start with a hyphen must be separated by blanks. For example, the following two command lines are equivalent and legal:
IDE允許你使用菜單來設置各種編譯選項,而命令行編譯器允許你使用字元「/」作為分隔符來設定這些編譯選項。你也可以使用連字元「-」來代替「/」,但是用「-」引出的參數之間必須用空格隔開。例如,下面兩個命令都是等同的也是合法的:
DCC -IC:\DELPHI -DDEBUG SORTNAME -$R- -$U+
DCC /IC:\DELPHI/DDEBUG SORTNAME /$R-/$U+
The first command line uses hyphens with at least one blank separating options. The second uses slashes and no separation is needed.
第一個編譯命令用「-」引出參數,且參數之間有多個空格分隔。第二個編譯命令用「/」引出參數,參數之間不必要分隔。
The following table lists the command-line options. In addition to the listed options, all single-letter compiler directives can be specified on the command line, as described in Compiler directive options.
下列表中列出所有的命令行參數。在附加的選項列表中,所有的單字元編譯器指令都可以在命令行編譯中使用,詳情請參照:編譯器指令。
Option Description
選項 描述
Aunit=alias 設置單元別名
B 編譯所有單元
CC 編譯控制台程序
CG 編譯圖形界面程序
Ddefines 編譯條件符號定義
Epath 可執行文件輸出路徑
Foffset 查找運行期間錯誤
GD 生成完整.Map文件
GP 生成.Map文件Public段
GS 生成.Map文件Segment段
H 輸出提示信息
Ipaths 文件包含路徑
J 生成.Obj目標文件
JP 生成C++類型.Obj目標文件
Kaddress Set image base address
LEpath 包.BPL文件輸出路徑
LNpath .dcp文件輸出路徑
LUpackage 使用運行期間包列表
M 編譯有改動的源文件
Npath dcu/dpu文件輸出目錄
Opaths .Obj文件(匯編目標代碼文件)路徑
P 按8.3格式文件名查找
Q 安靜模式
Rpaths 資源文件(.RES)路徑
TXext 目標文件擴展名
Upaths 單元文件路徑
V 為Turbo Debugger生成調試信息文件
VN 以.Giant格式生成包含命名空間的調試信息文件(將用於C++Builder)
VR 生成調試信息文件.rsm
W 輸出警告信息
Z Disable implicit compilation
$directive Compiler directives
--Help 顯示編譯選項的幫助。同樣的,如果你在命令行單獨輸入dcc32,也會顯示編譯選項的幫助。
--version 顯示產品名稱和版本
Compiler directive options
編譯器指令選項
Delphi supports the compiler directives described in Compiler directives. The $ and D command-line options allow you to change the default states of most compiler directives. Using $ and D on the command line is equivalent to inserting the corresponding compiler directive at the beginning of each source file compiled.
Delphi支持用編譯器指令關鍵字描述的編譯器指令。使用「$」和「D」命令行選項可以改變所有的默認編譯器狀態。用「$」和「D」命令行選項等同於在源文件的前面添加編譯器指令。
Switch directive option
編譯器指令選項開關
The $ option lets you change the default state of all of the switch directives. The syntax of a switch directive option is $ followed by the directive letter, followed by a plus (+) or a minus (-). For example:
「$」允許你改變每一種編譯器指令默認狀態。編譯器指令的語法是「$」後緊跟一個指令字元,再跟一個「-」或「+」。例如:
dcc32 MYSTUFF -$R-
compiles MYSTUFF.pas with range-checking turned off, while:
不使用邊界檢查編譯MYSTUFF.pas單元:
dcc32 MYSTUFF -$R+
compiles it with range checking turned on. Note that if a {$R+} or {$R-} compiler directive appears in the source text, it overrides the -$R command-line option.
使用界面檢查編譯MYSTUFF.pas單元。如果將編譯器指令{$R+}或{$R-}添加到源文件的開始,它將覆蓋從命令行傳入的參數。
You can repeat the -$ option in order to specify multiple compiler directives:
你可以用多個「$」來指定多個編譯器指令,如:
dcc32 MYSTUFF -$R--$I--$V--$U+
Alternately, the command-line compiler lets you write a list of directives (except for $M), separated by commas:
命令行編譯器允許作用逗號分隔的編譯器指定列表,如:
dcc32 MYSTUFF -$R-,I-,V-,U+
只需要用一個「$」符號。
Only one dollar sign ($) is needed.
注意,因為$M的格式不一樣,你不能在逗號分隔的指令列表中使用$M
Note that, because of its format, you cannot use the $M directive in a list of directives separated by commas.
Conditional defines option
條件編譯選項
The -D option lets you define conditional symbols, corresponding to the {$DEFINE symbol} compiler directive. The -D option must be followed by one or more conditional symbols separated by semicolons (;). For example, the following command line:
「-D」選項允許你定義一個編譯條件,符合你用{$DEFINE symbol}定義的編譯器指令。「-D」選項後必須跟隨一或多個用分號分隔的編譯條件符號,如下命令:
dcc32 MYSTUFF -DIOCHECK;DEBUG;LIST
defines three conditional symbols, iocheck, debug, and list, for the compilation of MYSTUFF.pas. This is equivalent to inserting:
定義了三個編譯條件符號:IOCHECK,DEBUG,LIST,用於MYSTUFF.pas單元中。這等同於在源文件中插入以下語句:
{$DEFINE IOCHECK}
{$DEFINE DEBUG}
{$DEFINE LIST}
at the beginning of MYSTUFF.pas. If you specify multiple -D directives, you can concatenate the symbol lists. Therefore:
如果你指定了多個「-D」選項,你可以聯接它們,如下:
dcc32 MYSTUFF -DIOCHECK-DDEBUG-DLIST
is equivalent to the first example.
等同於第一個例子。
Compiler mode options
編譯模式選項
A few options affect how the compiler itself functions. As with the other options, you can use these with either the hyphen or the slash format. Remember to separate the options with at least one blank.
有幾個選項能影響編譯器自身的功能。像其它選項一個,你可以使用「/」或「-」的格式。別忘了用至少一個空格分隔這些選項。
Make (-M) option
選項(-M)
The command-line compiler has built-in MAKE logic to aid in project maintenance. The -M option instructs command-line compiler to check all units upon which the file being compiled depends. Using this option results in a much quicker compile time.
命令行編譯器使用構造邏輯的方式來維護工程。「-M」選項指示編譯器檢查所有與編譯文件相關聯的文件。用這個參數會導致編譯時間增大。
A unit is recompiled under the following conditions:
一個源文件在下列情況下會重新編譯:
The source file for that unit has been modified since the unit file was created.
源文件被創建以來被修改過;
用「$I」指令包含的任何文件,用「$L」包含的任何.Obj文件,或用「$R」關聯的任何資源文件.Res,比源文件中的要新;
Any file included with the $I directive, any .OBJ file linked in by the $L directive, or any .res file referenced by the $R directive, is newer than the unit file.
The interface section of a unit referenced in a uses statement has changed.
單元介面部分interface的uses段有改動。
Units compiled with the -Z option are excluded from the make logic.
在單元編譯時指令「-Z」在構造邏輯期不被接受。
If you were applying this option to the previous example, the command would be:
如果你在上一個例子中使用這個指令,編譯命令就應該是:
dcc32 MYSTUFF -M
Build all (-B) option
編譯所有 選項(-B)
Instead of relying on the -M option to determine what needs to be updated, you can tell command-line compiler to update all units upon which your program depends using the -B option. You can't use -M and -B at the same time. The -B option is slower than the -M option and is usually unnecessary.
用於取代要知道哪些單元需要更新-M的選項,你可以使用-B選項來更新所有你的程序中關聯的單元。你不能在程序中同時使用-M和-B。選項-B比-M速度更慢,而且它並不是必需的。
If you were using this option in the previous example, the command would be
如果你在前一個例子中使用這個參數,編譯命令就應該是:
dcc32 MYSTUFF -B
Find error (-F) option
查找錯誤 選項(-F)
When a program terminates e to a runtime error, it displays an error code and the address at which the error occurred. By specifying that address in a -Faddress option, you can locate the statement in the source text that caused the error, provided your program and units were compiled with debug information enabled (via the $D compiler directive).
當一個程序由於運行期間錯誤而終止時,它會顯示一個錯誤號和錯誤地址在錯誤發生時。用-Faddress選項來指定錯誤地址,你在源文件中能找到引發錯誤的位置,如果你的程序和單元編譯時附加了調試信息(使用$D編譯器指令)。
In order for the command-line compiler to find the runtime error with -F, you must compile the program with all the same command-line parameters you used the first time you compiled it.
為了命令行編譯器能用-F選項查找運行期間錯誤,你必須傳遞與第一次編譯時相同的指令列表。
As mentioned previously, you must compile your program and units with debug information enabled for the command-line compiler to be able to find runtime errors. By default, all programs and units are compiled with debug information enabled, but if you turn it off, using a {$D-} compiler directive or a -$D- option, the command-line compiler will not be able to locate runtime errors.
先前提到過,你的程序和單元必須啟用調試信息,命令行編譯器才能查找運行期間錯誤。默認情況下,所有的程序和單都是啟用調試信息的,除非你用{-D}或-$D-指令關閉它,這樣,命令行編譯器就不能查找運行期間錯誤了。
Use packages (-LU) option
使用包(-LU)選項
Use the -LU option to list additional runtime packages that you want to use in the application being compiled. Runtime packages already listed in the Project Options dialog box need not be repeated on the command line.
使用-LU選項來在編譯時添加你應用程序中要用到的運行期間包。運行期間包已經在「工程選項」對話框中列舉的,不必再在命令行中添加。
Disable implicit compilation (-Z) option
(此選項在delphi6.0/7.0中有不同描述,在此不作翻譯)
The -Z option prevents packages and units from being implicitly recompiled later. With packages, it is equivalent to placing {$ IMPLICITBUILD OFF} in the .dpk file. Use -Z when compiling packages that provide low-level functionality, that change infrequently between builds, or whose source code will not be distributed.
Target file extension (-TX) option
目標文件擴展名(-TX)選項
The -TX option lets you override the default extension for the output file. For example,
選項-TX允許你改寫默認的輸出文件擴展名。例如:
dcc32 MYSTUFF -TXSYS
generates compiled output in a file called MYSTUFF.SYS.
生成的將是一個叫做MYSTUFF.SYS的文件。
Quiet (-Q) option
安靜模式(-Q)選項
The quiet mode option suppresses the printing of file names and line numbers ring compilation. When the command-line compiler is invoked with the quiet mode option
安靜模式選項禁止在編譯時顯示文件名及代碼行數,如果命令行編譯器調用這個選項的話。
dcc32 MYSTUFF -Q its output is limited to the startup right message and the usual statistics at the end of compilation. If any errors occur, they will be reported.
它的輸出僅限於起始時行版權信息以及結尾的統計信息。當然,如果發生錯誤,它也會輸出。
DCC32.CFG file
DCC32.CFG配置文件
You can set up a list of options in a configuration file called DCC32.CFG, which will then be used in addition to the options entered on the command line. Each line in configuration file corresponds to an extra command-line argument inserted before the actual command-line arguments. Thus, by creating a configuration file, you can change the default setting of any command-line option.
你可以設置一個編譯選項列表到一個叫做DCC32.CFG的配置文件中,它將用於編譯時附加到命令行參數後。配置文件的每一行都相當於一個額外的命令行參數插入到實際的命令行參數前(注意,是實際參數前)。因而,你可以使用這個配置文件改變一些命令行參數的默認設置。
The command-line compiler lets you enter the same command-line option several times, ignoring all but the last occurrence. This way, even though you've changed some settings with a configuration file, you can still override them on the command line.
命令行編譯器允許你輸入相同的命令行參數,它將忽略所有除最後一個之外。這個的話,盡管通過配置文件你可以改變一些設置,你仍然可以覆蓋它使用命令行參數。
When dcc32 starts, it looks for DCC32.CFG in the current directory. If the file isn't found there, dcc32 looks in the directory where DCC32.EXE resides.
當dcc32啟動時,它查找DCC32.CFG文件在當前目錄。如果文件沒有找到,dcc32會查找它所在的目錄。
Here's an example DCC32.CFG file, defining some default directories for include, object, and unit files, and changing the default states of the $O and $R compiler directives:
以下是一個DCC32.CFG配置文件的例子,定義了關於文件包含、OBJ文件包含、單元文件搜索路徑信息,並改變了編譯器指令$O和$R的默認值。
-IC:\DELPHI\INC;C:\DELPHI\SRC
-OC:\DELPHI\ASM
-UC:\DELPHI\UNITS
-$R+
-$O-
Now, if you type:
現在,如果你輸入:
dcc32 MYSTUFF
the compiler performs as if you had typed the following:
編譯器把它當作你輸入如下命令:
dcc32 -IC:\DELPHI\INC;C:\DELPHI\SRC -OC:\DELPHI\ASM -UC:\DELPHI\UNITS -$R+ -$O- MYSTUFF
Debug options
調試選項
The compiler has two sets of command-line options that enable you to generate external debugging information: the map file options and the debug info options.
編譯器有兩個命令行參數可以生成外部調試信息:MAP文件選項和調試信息選項。
Map file (-G) options
Map文件(-G)選項
The -G option instructs the command-line compiler to generate a .map file that shows the layout of the executable file. Unlike the binary format of executable and .dcu files, a .map file is a legible text file that can be output on a printer or loaded into the editor. The -G option must be followed by the letter S, P, or D to indicate the desired level of information in the .map file. A .MAP file is divided into three sections:
選項-G指示命令行編譯器生成一個.map文件來查看一個可執行文件的布局。不同於可二進制的可執行文件和.dcu文件,.map文件是一個可讀的文本文件,可以被列印或是其它文本編輯器編輯。選項-G後必須跟字元S、P或D,去決定你想要在.map文件列出的信息。一個.MAP文件被分成三個節:
Segment
Publics
Line Numbers
-GS outputs only the Segment section, -GP outputs the Segment and Publics section, and -GD outputs all three sections. -GD also generates a .DRC file that contains tables of all string constants declared using the resourcestring keyword.
-GS選項只輸出Segment Section,-GS選項輸出Segment和Publics,-GD輸出所有的三個Sections.-GD選項也生成一個擴展名為.DRC的文件包含所有的用resourcestring關鍵字聲明的字元串常量。
For moles (program and units) compiled in the {$D+,L+} state (the default), the Publics section shows all global variables, proceres, and functions, and the Line Numbers section shows line numbers for all proceres and functions in the mole. In the {$D+,L-} state, only symbols defined in a unit's interface part are listed in the Publics section. For moles compiled in the {$D-} state, there are no entries in the Line Numbers section.
用默認的編譯選項{$D+,L+}編譯模塊(程序或單元),Publics Section列舉所有的全局變數、過程和函數,Line Numbers Section列舉模塊中所有的過程和函數的行號。如果用{$D+,L-}編譯選項編譯模塊,Publics Section中僅列舉在單元的interface部分定義的符號。如果用{$D-}選項編譯模塊,在Line Numbers Section沒有任何入口。
Debug info (-V) options
調度選項(-V)
The -V options (-V, -VN. and -VR), which cause the compiler to generate debug information, can be combined on the command line.
選項-V、-VN、-VR會指示編譯器生成調試信息,它們能在命令行中組合使用。
Generate Turbo Debugger debug info (-V) option
生成Turbo Debugger使用的調試信息的選項(-V)
When you specify the -V option on the command line, the compiler appends Turbo Debugger 5.0-compatible external debug information at the end of the executable file. Turbo Debugger includes both source- and machine-level debugging and powerful breakpoints.
當你在命令行中使用-V選項時,編譯器會在可執行文件的末尾附加與Turbo Debugger5.0一致的外部調試信息。Turbo Debugger包含代碼和硬體級別的強大的斷點。
Even though the debug information generated by -V makes the resulting executable file larger, it does not affect the actual code in the executable, and does not require additional memory to run the program.
雖然附加調試信息到查執行文件中會使可執行文件增大,但是它並不影響實際可執行文件中的可執行代碼,也不需要額外的內存來啟動程序。
The extent of debug information appended to the executable file depends on the setting of the $D and $L compiler directives in each of the moles (program and units) that make up the application. For moles compiled in the {$D+,L+} state, which is the default, all constant, variable, type, procere, and function symbols are known to the debugger. In the {$D+,L-} state, only symbols defined in a unit's interface section are known to the debugger. In the {$D-} state, no line-number records are generated, so the debugger cannot display source lines whe
㈢ c語言編譯預處理
編譯,編譯程序讀取源程序(字元流),對之進行詞法和語法的分析,將高級語言指令轉換為功能等效的匯編代碼,再由匯編程序轉換為機器語言,並且按照操作系統對可執行文件格式的要求鏈接生成可執行程序。
如果用一張圖來表示:
讀取c源程序,對其中的偽指令(以#開頭的指令)和特殊符號進行處理
[析] 偽指令主要包括以下四個方面
(1)宏定義指令,如#define Name TokenString,#undef等。對於前一個偽指令,預編譯所要做的是將程序中的所有Name用TokenString替換,但作為字元串常量的Name則不被替換。對於後者,則將取消對某個宏的定義,使以後該串的'出現不再被替換。
(2)條件編譯指令,如#ifdef,#ifndef,#else,#elif,#endif,等等。這些偽指令的引入使得程序員可以通過定義不同的宏來決定編譯程序對哪些代碼進行處理。預編譯程序將根據有關的文件,將那些不必要的代碼過濾掉
(3)頭文件包含指令,如#include "FileName"或者#include 等。在頭文件中一般用偽指令#define定義了大量的宏(最常見的是字元常量),同時包含有各種外部符號的聲明。採用頭文件的目的主要是為了使某些定義可以供多個不同的C源程序使用。因為在需要用到這些定義的C源程序中,只需加上一條#include語句即可,而不必再在此文件中將這些定義重復一遍。預編譯程序將把頭文件中的定義統統都加入到它所產生的輸出文件中,以供編譯程序對之進行處理。
包含到c源程序中的頭文件可以是系統提供的,這些頭文件一般被放在/usr/include目錄下。在程序中#include它們要使用尖括弧(<>)。另外開發人員也可以定義自己的頭文件,這些文件一般與c源程序放在同一目錄下,此時在#include中要用雙引號("")。
(4)特殊符號,預編譯程序可以識別一些特殊的符號。例如在源程序中出現的LINE標識將被解釋為當前行號(十進制數),FILE則被解釋為當前被編譯的C源程序的名稱。預編譯程序對於在源程序中出現的這些串將用合適的值進行替換。
注意:
預編譯程序所完成的基本上是對源程序的「替代」工作。經過此種替代,生成一個沒有宏定義、沒有條件編譯指令、沒有特殊符號的輸出文件。這個文件的含義同沒有經過預處理的源文件是相同的,但內容有所不同。下一步,此輸出文件將作為編譯程序的輸出而被翻譯成為機器指令。
㈣ 編譯程序包括哪幾個主要組成部分
編譯過程分為分析和綜合兩個部分,並進一步劃分為詞法分析、語法分析、語義分析、代碼優化、存儲分配和代碼生成等六個相繼的邏輯步驟。這六個步驟只表示編譯程序各部分之間的邏輯聯系,而不是時間關系。
編譯過程既可以按照這六個邏輯步驟順序地執行,也可以按照平行互鎖方式去執行。在確定編譯程序的具體結構時,常常分若干遍實現。對於源程序或中間語言程序,從頭到尾掃視一次並實現所規定的工作稱作一遍。每一遍可以完成一個或相連幾個邏輯步驟的工作。
(4)編譯程序組合指令擴展閱讀:
對於c編譯程序來說,其語言的特點如下:
1、c語言是一種結構化語言。它層次清晰,便於按模塊化方式組織程序,易於調試和維護,而且表現能力和處理能力極強。
2、c語言具有豐富的運算符和數據類型,便於實現各類復雜的數據結構。它還可以直接訪問內存的物理地址,進行位(bit)一級的操作。
3、由於c語言實現了對硬體的編程操作,因此集高級語言和低級語言的功能於一體。它既可用於系統軟體的開發,也適合於應用軟體的開發。
4、此外,c語言還具有效率高、可移植性強等特點。因此它廣泛地移植到了各類各型計算機上,從而形成了多種版本。
㈤ 如何編程
編程是編定程序的中文簡稱,就是讓計算機代碼解決某個問題,對某個計算體系規定一定的運算方式,使計算體系按照該計算方式運行,並最終得到相應結果的過程。
為了使計算機能夠理解人的意圖,人類就必須將需解決的問題的思路、方法和手段通過計算機能夠理解的形式告訴計算機,使得計算機能夠根據人的指令一步一步去工作,完成某種特定的任務。這種人和計算體系之間交流的過程就是編程。
編程:設計具備邏輯流動作用的一種「可控體系」【註:編程不一定是針對計算機程序而言的,針對具備邏輯計算力的體系,都可以算編程。】
一、編程語言
機器語言:是機器能直接識別的程序語言或指令代碼。計算機是基於二進制的0和1來處理運算,這種0和1的組合指令又叫做機器語言。
編譯器:就像中國人和外國人說話要把中文翻譯成英文一樣。代碼要運行,就要把代碼翻譯成機器語言,這個過程叫做編譯,用來處理代碼編譯的軟體叫做編譯器。
編程語言:用來定義計算機程序的形式語言,用來向計算機發出指令。簡單來說,就是人類和計算機進行交流的語言。
二、計算機如何處理程序?
按照察賀馮·諾依曼存儲程序的原理,計算機的工作流程大致如下:
用戶打開程序,程序開始執行;
操作系統將程序內容和相關數據送入計算機的內存;
CPU根據程序內容從內存中讀取指令;
CPU分析、處理指令褲沒畢,並為取胡芹下一條指令做准備;
取下一條指令並分析、處理,如此重復操作,直至執行完程序中的全部指令;
最後,將計算的結果放入指令指定的存儲器地址。
㈥ 一個典型的編譯程序通常由哪些部分組成
1、詞法分析
詞法分析的任務是對由字元組成的單詞進行處理,從左至右逐個字元地對源程序進行掃描,產生一個個的單詞符號,把作為字元串的源程序改造成為單詞符號串的中間程序。執行詞法分析的程序稱為詞法分析程序或掃描器。
2、語法分析
編譯程序的語法分析器以單詞符號作為輸入,分析單詞符號串是否形成符合語法規則的語法單位,如表達式、賦值、循環等,最後看是否構成一個符合要求的程序,按該語言使用的語法規則分析檢查每條語句是否有正確的邏輯結構,程序是最終的一個語法單位。
3、中間代碼生成
中間代碼是源程序的一種內部表示,或稱中間語言。中間代碼的作用是可使編譯程序的結構在邏輯上更為簡單明確,特別是可使目標代碼的優化比較容易實現。中間代碼即為中間語言程序,中間語言的復雜性介於源程序語言和機器語言之間。
4、代碼優化
代碼優化是指對程序進行多種等價變換,使得從變換後的程序出發,能生成更有效的目標代碼。所謂等價,是指不改變程序的運行結果。所謂有效,主要指目標代碼運行時間較短,以及佔用的存儲空間較小。這種變換稱為優化。
5、目標代碼生成
目標代碼生成是編譯的最後一個階段。目標代碼生成器把語法分析後或優化後的中間代碼變換成目標代碼。
(6)編譯程序組合指令擴展閱讀:
編譯程序把用高級程序設計語言書寫的源程序,翻譯成等價的機器語言格式目標程序的翻譯程序。編譯程序屬於採用生成性實現途徑實現的翻譯程序。它以高級程序設計語言書寫的源程序作為輸入,而以匯編語言或機器語言表示的目標程序作為輸出。
編譯出的目標程序通常還要經歷運行階段,以便在運行程序的支持下運行,加工初始數據,算出所需的計算結果。
編譯程序的實現演算法較為復雜。這是因為它所翻譯的語句與目標語言的指令不是一一對應關系,而是一多對應關系;同時也因為它要處理遞歸調用、動態存儲分配、多種數據類型,以及語句間的緊密依賴關系。
但是,由於高級程序設計語言書寫的程序具有易讀、易移植和表達能力強等特點,編譯程序廣泛地用於翻譯規模較大、復雜性較高、且需要高效運行的高級語言書寫的源程序。
㈦ 由編譯程序將多條指令組合成一條指令,這種技術稱做_______。
C. 超長指令字技術。
VLIW:(Very Long Instruction Word,超長指令字)一種非常長的指令組指鬧爛彎芹合,它把許多條指唯漏令連在一起,增加了運算的速度。
㈧ C語言的按照標識符、關鍵字、常用編譯指令有哪些
我們可以在C源程序中插入傳給編譯程序的各中指令,這些指令被稱為預處理器指令,它們擴充了程序設計的環境。現把常用的預處理命令總結如下:
1. 預處理程序
按照ANSI標準的定義,預處理程序應該處理以下指令:
#if #ifdef #ifndef #else #elif
#endif
#define
#undef
#line
#error
#pragma
#include
顯然,上述所有的12個預處理指令都以符號#開始,,每條預處理指令必須獨佔一行。
2. #define
#define指令定義一個標識符和一個串(也就是字元集),在源程序中發現該標識符時,都用該串替換之。這種標識符稱為宏名字,相應的替換稱為宏代換。一般形式如下:
#define macro-name char-sequence
這種語句不用分號結尾。宏名字和串之間可以有多個空白符,但串開始後只能以新行終止。
例如:我們使用LEFT代表1,用RIGHT代表0,我們使用兩個#define指令:
#define LEFT 1
#define RIGHT 0
每當在源程序中遇到LEFT或RIGHT時,編譯程序都用1或0替換。
定義一個宏名字之後,可以在其他宏定義中使用,例如:
#define ONE 1
#define TWO ONE+ONE
#define THREE ONE+TWO
宏代換就是用相關的串替代標識符。因此,如果希望定義一條標准錯誤信息時,可以如下定義:
#define ERROR_MS 「Standard error on input \n」
如果一個串長於一行,可在行尾用反斜線」\」續行,如下:
#define LONG_STRING 「This is a very very long \
String that is used as an example」
3. #error
#error指令強制編譯程序停止編譯,它主要用於程序調試。#error指令的一般形式是:
#error error-message
注意,宏串error-message不用雙引號包圍。遇到#error指令時,錯誤信息被顯示,可能同時還顯示編譯程序作者預先定義的其他內容。
4. #include
程序中的#include指令要求編譯程序讀入另一個源文件。被讀入文件的名字必須用雙引號(「」)或一對尖括弧(<>)包圍,例如:
#include 「stdio.h」
#include <stdio.h>
都使C編譯程序讀入並編譯頭文件以用於I/O系統庫函數。
包含文件中可以包含其他#include指令,稱為嵌套包含。允許的最大嵌套深度隨編譯器而變。
文件名被雙括弧或尖括弧包圍決定了對指定文件的搜索方式。文件名被尖括弧包圍時,搜索按編譯程序作者的定義進行,一般用於搜索某些專門放置包含文件的特殊目錄。當文件名被雙括弧包圍時,搜索按編譯程序實時的規定進行,一般搜索當前目錄。如未發現,再按尖括弧包圍時的辦法重新搜索一次。
通常,絕大多數程序員使用尖括弧包圍標準的頭文件,雙引號用於包圍與當前程序相關的文件名。
5. 條件編譯指令
若干編譯指令允許程序員有選擇的編譯程序源代碼的不同部分,這種過程稱為條件編譯。
5.1#if、#else、#elif #endif
條件編譯指令中最常用的或許是#if,#else,#elif和#endif。這些指令允許程序員根據常數表達式的結果有條件的包圍部分代碼。
#if的一般形式是:
#if constant-expression
Statement sequence
#endif
如#if後的常數表達式為真,則#if和#endif中間的代碼被編譯,否則忽略該代碼段。#endif標記#if塊的結束。
#else指令的作用與C語言的else相似,#if指令失敗時它可以作為備選指令。例如:
#include <stdio.h>
#define MAX 100
Int main(void)
{
#if MAX>99
printf(「Compiled for array greater than 99.\n」);
#else
printf(「Complied for small array.\n」);
#endif
return 0;
}
㈨ 什麼是編譯程序和匯編程序
分類: 電腦/網路
問題描述:
什麼是編譯程序和匯編程序?他們有什麼區別?和機器語言、高級語言匯編語言有什麼樣的聯系
解析:
用匯編語言或高級語言編寫的程序,必須先送入計算機,經過轉換成用機器語言表示的目標程序(這個過程即編譯),才能由計算機執行。執行轉換過程的程序叫編譯程序。匯編程序是指沒有編譯過的匯編語言源文件。
編譯程序轉換過的叫目標程序,也就是機器語言。
編譯程序的工作情況有三種:匯編型、解釋型和編譯型。匯編型編稿冊譯程序用來將匯編語言編寫的程序,按照一一對應的關系,轉換鄭鬥成用機器語言表示的程序。解釋型編譯程序將高喊敬磨級語言程序的一個語句,先解釋成為一組機器語言的指令,然後立即執行,執行完了,取下一組語句解釋和執行,如此繼續到完成一個程序為止。用解釋型編譯程序,執行速度很慢,但可以進行人和計算機的"對話",隨時可以修改高級語言的程序。BASIC語言就是解釋型高級語言。編譯型編譯程序將高級語言編寫的程序,一次就會部翻譯成機器語言表示的程序,而且過程進行很快,在過程中,不能進行人機對話修改。FORTRAN語言就是編譯型高級語言。
㈩ 什麼是編譯程序
編譯程序指將某一種程序設計語言寫的程序翻譯成等價的另一種語言的程序的程序, 稱之為編譯程序
編譯程序也稱為編譯器,是指把用高級程序設計語言書寫的源程序,翻譯成等價的機器語言格式目標程序的翻譯程序。編譯程序屬於採用生成性實現途徑實現的翻譯程序。
它以高級程序設計語言書寫的源程序作為輸入,而以匯編語言或機器語言表示的目標程序作為輸出。編譯出的目標程序通常還要經歷運行階段,以便在運行程序的支持下運行,加工初始數據,算出所需的計算結果。
編譯程序的實現演算法較為復雜,這是因為它所翻譯的語句與目標語言的指令不是一一對應關系,而是一多對應關系,同時也因為它要處理遞歸調用、動態存儲分配、多種數據類型,以及語句間的緊密依賴關系。
由於高級程序設計語言書寫的程序具有易讀、易移植和表達能力強等特點,編譯程序廣泛地用於翻譯規模較大、復雜性較高、且需要高效運行的高級語言書寫的源程序。
(10)編譯程序組合指令擴展閱讀:
編譯流程分為了四個步驟:
1.預處理,生成預編譯文件(.文件)
2.編譯,生成匯編代碼(.s文件)
3.匯編,生成目標文件(.o文件)
4.鏈接,生成可執行文件