Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Binary Machine Modern high-level programming languages are designed to make programming easier. On the other end, the low level, all modern digital.

Similar presentations


Presentation on theme: "The Binary Machine Modern high-level programming languages are designed to make programming easier. On the other end, the low level, all modern digital."— Presentation transcript:

1 The Binary Machine Modern high-level programming languages are designed to make programming easier. On the other end, the low level, all modern digital computers understand only machine language. This means that a program written in a high-level language must be translated into machine language. Translation is performed by an assembler, an interpreter, or a compiler. A computer has a hard-wired instruction set unique to that computer.

2 The Binary Machine The instruction set is etched into the computer’s microprocessor chip. High-level -----> Translator -----> Low-level Source code ---------------------------> Object code Source code is what goes into a program translator. Object code is what comes out. At the low-level, all modern digital computers store programs and information in binary form.

3 Binary Representations Modern digital computer hardware circuitry is based on on-off switching. Thus, a computer can distinguish between only the two values “on” (1) and “off” (0). This means information must be represented in binary form. Some terminology: bit - binary digit. byte - 8 bits. word - 2 bytes or 16 bits.

4 Binary Representations Example: Computer memory is measured in bytes. 64 MB means 64 megabytes or 64 million bytes or 8 x 64 = 512 million bits. Numbers are represented in binary (base 2) notation. Example: 235 in decimal notation is 11101011 in binary notation. 235 = 2 x 10 2 + 3 x 10 1 + 5 x 10 0 11101011 = 1 x 2 7 + 1 x 2 6 + 1 x 2 5 + 0 x 2 4 + 1 x 2 3 + 0 x 2 2 + 1 x 2 1 + 1 x 2 0

5 Binary Representations There’s a decimal-to-binary and binary-to- decimal calculator in Module 6 of The Analytical Engine Website. Characters are represented by coding them as integers. A commonly used character code is ASCII (American Standard Code for Information Interchange). Example: The letter A is represented by 65 or 01000001. A right parenthesis ) is represented by 41 or 00101001.

6 Encoding Instructions Instructions are also encoded in binary. accumulator - a location where intermediate results are stored. Sample coded instructions: Code Info Action 00000100 X Load accumulator with contents of memory location X 00000101 X Store accumulator value in memory location X 00001111 X Halt execution 00000000 X Add contents of memory location X to accumulator

7 Encoding Instructions With this coding, a simple machine- language program might look like this: 00000100 10000000 00000000 10000001 00000101 10000000 00001111 00000000 Here’s what it says: Load accumulator with contents of 128. Add contents of 129 to accumulator. Store accumulator contents in 128. Halt.

8 Encoding Instructions As you might guess, programming in machine language is hard. Early programmers developed mnemonics for remembering instructions. The above machine-language program might be remembered as follows: (x = cell 128, y = cell 129) Load x Add y Store x Halt

9 Encoding Instructions The next step was to write a program which would translate these mnemonics to machine language, thereby sparing a programmer the grief of programming directly in machine language. This led to the first program translator. assembler - a program that takes an assembly language as its input source code and produces machine language as its output object code. The PIPPIN assembler.

10 Beyond the Assembler Assembly-language code is fast and efficient, but hard to write. Using a higher-level language closer to our native language would make programming easier. The idea is to move away from dealing with the computer at its level and work more at our level. When programming at a high level, we don’t want to think about the details of the computer our program will run on.

11 Types of Languages Modern high-level programming languages come in two flavors depending on the type of translator used to take source code and produce object code. interpreter - a translator which translates one line of source code and instructs the computer to perform the resulting object code before translating another line of source code. compiler - a translator which translates all the source code and produces a complete machine-language program.

12 Interpreted Languages Examples include BASIC, LISP, JavaScript. Advantages: - Interpreters are easy to write. - Errors are more easily localized. Disadvantages: - Interpreters are slow. - A source-code line will be translated as often as it is encountered. For example, a line of code in a loop that is repeated 1000 times will be translated 1000 times.

13 Compiled Languages Examples include FORTRAN, C, Java. Advantage: - After compilation, execution is fast. Disadvantage: - Localizing errors is more difficult.

14 Language Groups 1.Imperative - the fundamental unit is a procedure called by the main program. Examples are FORTRAN, Pascal, Ada. 2.Functional - processes are defined as functions with no main program. An example is LISP. 3.Declarative - the emphasis is on I/O as opposed to processing algorithms. Examples are COBOL, Prolog. 4.Object-oriented - hybrids organized around programming “objects”. Examples are C++, Java.

15 Language Translation Translation of a high-level language into machine language involves three steps: 1.Scanning - breaking the source code into its smallest meaningful pieces or tokens. This is what we do when we read a sentence and note the words it contains. 2.Parsing - arranging the tokens into a sensible logical structure. This is what we do when we recognize nouns, verbs, adjectives, etc. in a sentence. 3.Code generation - generating the machine language object code. This is what we do when we paraphrase a sentence for a kid.

16 Language Generations Languages are characterized by how far they are from what computers do and how close they are to what people do. 1.First generation - machine languages. 2.Second generation - assembly languages and assemblers. 3.Third generation - interpreted and compiled languages. 4.Fourth generation - languages that give “computational power to non- programmers.”


Download ppt "The Binary Machine Modern high-level programming languages are designed to make programming easier. On the other end, the low level, all modern digital."

Similar presentations


Ads by Google