1 / 31

程式語言

程式語言. 語言是用來溝通的工具 , 人類有人類的語言 , 電腦也有電腦的語言。我們必須將要電腦做的事情 , 以電腦了解的語言來表達 , 電腦才能替我們完成工作。要和電腦溝通就要用 程式語言 (Programming Language) 。 程式就是利用程式語言的敘述 , 遵照其一定的規則及所要處理工作的順序 , 編排而成的一連串命令。. 程式語言. 依電腦可接受的程度來區分 , 程式語言可分為以下幾種:. 機械語言.

mort
Download Presentation

程式語言

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 程式語言 • 語言是用來溝通的工具, 人類有人類的語言, 電腦也有電腦的語言。我們必須將要電腦做的事情,以電腦了解的語言來表達, 電腦才能替我們完成工作。要和電腦溝通就要用程式語言(Programming Language)。 • 程式就是利用程式語言的敘述, 遵照其一定的規則及所要處理工作的順序, 編排而成的一連串命令。

  2. 程式語言 • 依電腦可接受的程度來區分, 程式語言可分為以下幾種:

  3. 機械語言 • 電腦所使用的語言就是機械語言(Machine Language) , 它們都是由 0 與 1 數字所組成, 跟人類的思考模式完全不同, 使得學習與撰寫上都十分困難, 更別說是拿來發展程式。

  4. 組合語言 • 組合語言與機械語言仍然相當接近, 它改用一些特別的字元來代替一大串 0與 1 所組成的機械語言碼, 增加了程式的可讀性。

  5. 組合語言 • 由於以機械語言與組合語言來編寫程式需要非常瞭解電腦的內部構造, 並且直接控制電腦硬體, 因此我們稱此兩者為低階語言。 • 對於缺乏電腦專業知識背景的人, 這兩種語言學習起來還是滿困難的, 所以才有以下高階語言的發展。

  6. 高階語言 • 高階語言是比較接近人類使用的電腦程式語言。這類電腦語言採用類似英文的字彙及數學運算式的語法來敘述人類要電腦做的事, 因此用高階語言撰寫程式比較輕鬆, 而程式也比較容易閱讀。 • 目前較常用的高階語言有:Visual Basic、Delphi、Java...等;早期流行的有BASIC、FORTRAN、COBOL、C...等。

  7. Chapter 7 Low-Level Programming Languages

  8. Computer Operations • A computer is a programmable electronic device that can store, retrieve, and process data • Data and instructions to manipulate the data are logically the same and can be stored in the same place • Store, retrieve, and process are actions that the computer can perform on data

  9. Machine Language • Machine languageThe instructions built into the hardware of a particular computer • Initially, humans had no choice but to write programs in machine language because other programming languages had not yet been invented

  10. Machine Language • Every processor type has its own set of specific machine instructions • The relationship between the processor and the instructions it can carry out is completely integrated • Each machine-language instruction does only one very low-level task

  11. Pep/7: A Virtual Computer • Virtual computer A hypothetical machine designed to contain the important features of real computers that we want to illustrate • Pep/7 • designed by Stanley Warford • has 32 machine-language instructions • We are only going to examine a few of these instructions

  12. Features in Pep/7 • The memory unit is made up of 4,096 bytes • Pep/7 Registers/Status Bits Covered • The program counter (PC) (contains the address of the next instruction to be executed) • The instruction register (IR) (contains a copy of the instruction being executed) • The accumulator (A register) • Status bit N (1 if A register is negative; 0 otherwise) • Status bit Z (1 if the A register is 0; and 0 otherwise)

  13. Features in Pep/7 Program Counter 應為16bits,雖然前4碼都為0 Figure 7.1 Pep/7’s architecture

  14. Instruction Format • There are two parts to an instruction • The 8-bit instruction specifier • And optionally, the 16-bit operand specifier Figure 7.2 The Pep/7 instruction format

  15. Instruction Format • The instruction specifier is made up of several sections • The operation code • The register specifier • The addressing-mode specifier

  16. Instruction Format • The operation code specifies which instruction is to be carried out • The 1-bit register specifier is 0 if register A (the accumulator) is involved, which is the case in this chapter. • The 2-bit addressing-mode specifier says how to interpret the operand part of the instruction

  17. Instruction Format Figure 7.3 Difference between immediate-mode and direct-mode addressing

  18. Some Sample Instructions Figure 7.3 Subset of Pep/7 instructions

  19. A Program Example • Let’s write "Hello" on the screen Page 200

  20. Pep/7 Simulator • A program that behaves just like the Pep/7 virtual machine behaves • To run a program, we enter the hexadecimal code, byte by byte with blanks between each Page 202

  21. Assembly Language • Assembly languages A language that uses mnemonic codes to represent machine-language instructions • The programmer uses these alphanumeric codes in place of binary digits • A program called an assembler reads each of the instructions in mnemonic form and translates it into the machine-language equivalent

  22. Pep/7 Assembly Language

  23. Figure 7.5 Assembly Process

  24. Pr0502 CHARI h#000D,d ;Input first character CHARI h#000E,d ;Input second character CHARO h#000E,d ;Output second character CHARO h#000D,d ;Output first character STOP .BLOCK d#1 ;Storage for first char .BLOCK d#1 ;Storage for second char .END

  25. Assembler Listing Object Addr code Mnemon Operand Comment 0000 D9000D CHARI h#000D,d ;Input first character 0003 D9000E CHARI h#000E,d ;Input second character 0006 E1000E CHARO h#000E,d ;Output second character 0009 E1000D CHARO h#000D,d ;Output first character 000C 00 STOP 000D 00 .BLOCK d#1 ;Storage for first char 000E 00 .BLOCK d#1 ;Storage for second char 000F .END

  26. Pr0502-modified CHARI c1,d ;Input first character CHARI c2,d ;Input second character CHARO c2,d ;Output second character CHARO c1,d ;Output first character STOP c1: .BLOCK d#1 ;Storage for first char c2: .BLOCK d#1 ;Storage for second char .END

  27. Assembler Listing Object Addr code Symbol Mnemon Operand Comment 0000 D9000D CHARI c1,d ;Input first character 0003 D9000E CHARI c2,d ;Input second character 0006 E1000E CHARO c2,d ;Output second character 0009 E1000D CHARO c1,d ;Output first character 000C 00 STOP 000D 00c1: .BLOCK d#1 ;Storage for first char 000E 00c2: .BLOCK d#1 ;Storage for second char 000F .END Symbol Value Symbol Value c1 000D c2 000E

  28. A New Program

  29. Our Completed Program Page 217 Pseudo Code 7-22

  30. Object Addr code Symbol Mnemon Operand 0000 70000B BR Main 0003 0000 sum: .WORD d#0 0005 0000 num1: .BLOCK d#2 0007 0000 num2: .BLOCK d#2 0009 0000 num3: .BLOCK d#2 000B 090003 Main: LOADA sum,d 000E E90005 DECI num1,d 0011 190005 ADDA num1,d 0014 E90007 DECI num2,d 0017 190007 ADDA num2,d 001A E90009 DECI num3,d 001D 190009 ADDA num3,d 0020 110003 STOREA sum,d 0023 F10003 DECO sum,d 0026 00 STOP 0027 .END Symbol Value Symbol Value Main 000B num1 0005 num2 0007 num3 0009 Sum 0003

  31. Status Bits Status bits allow a program to make a choice. BRLT Set the PC to the operand, if N is 1 (A register is less than zero) BREQ Set the PC to operand, if Z is 1 (A register is equal to zero)

More Related