翻譯器 (運算)

出自維基百科,自由嘅百科全書

翻譯器粵拼faan1 jik6 hei3英文translator),又有叫程式語言處理器programming language processor),喺程式編寫上係一個籠統嘅詞,泛指任何將電腦碼由一種電腦語言轉換做第種電腦語言嘅架生[1]。一種比較常見嘅負責將高階程式語言(好似係 C++ 或者 Java 等等)翻譯做機械語言組合語言程式電腦唔能夠直接噉理解高階語言,所以喺一位用家用高階語言寫好咗段碼之後,部電腦需要用翻譯器將段碼變成機械碼(machine code)呢種電腦能夠直接讀同處理嘅碼;除此之外,有陣時翻譯器又會俾人攞嚟將一種程式語言嘅碼轉做第種同階語言嘅,用途在於等用家可以輕易噉將自己寫嘅碼搬去第部-可能支援嘅程式語言唔同嘅-電腦嗰度行[2][3]

[編輯]

想像以下嘅 C 程式語言[4]

if (ax < bx) { // 如果 ax 細過 bx,將 x 設做 -1。
    x = -1;
} else { // 如果唔係,就將 x 設做 1。
    x = 1;
}

一個由 C 到組合語言嘅翻譯器會將段碼轉換成以下(功能完全相同)嘅組合語言碼:

	cmp 	ax, bx  	; 「cmp」係英文「compare」嘅簡寫,呢個指令叫部電腦比較 ax 同 bx。
	jl  	axLess          ; 如果比較結果係 ax 細啲,跳去「axless」嗰指令。
	mov 	word [X], 1     ; 將 x 設做 1,如果 ax 細過 bx,部電腦會跳過呢行指令。
	jmp 	Both            ; 做咗「將 x 設做 1」喇,所以要跳去 Both 嗰度(如果有呢行指令,部電腦就會將 x 設做 -1 再設做 1)。
axLess: 
	mov 	word [X], -1    ; 將 x 設做 -1。
Both:

睇埋[編輯]

[編輯]

  1. Thornton, Scott (2017-02-17). "What are compilers, translators, interpreters, and assemblers?". MicrocontrollerTips. Archived from the original on 2019-07-19.
  2. "Translators And Utilities For Program Development". Software Handbook (PDF). Intel Corporation. 1984 [1983]. p. 3-1. 230786-001.
  3. Schuerer, Katja; Letondal, Catherine; Deveaud, Eric (2008-02-04) [2003-01-06]. "Chapter 5. Program execution, Section 5.2. Interpreter and Compiler". Introduction to Programming using Python - Programming Course for Biologists at the Pasteur Institute. pasteur.fr. Pasteur Institute. pp. 37–40.
  4. Decision-Making in Assembly Language. UMBC.

參考[編輯]