### Evolution of the art of "programming a computer"

• Recall: What is a computer program ???

• Computer program:

• Computer program =

a series of computer instruction (a.k.a. machine instructions) that tells the computer what operations it needs to perform at each step

+

a number of variables used to store information (values) used by instructions in the computer program

• Machine Instructions

• Machine instruction:

• Machine instruction = a binary number that encodes an action that a computer must perform

 Each machine instructions is represented by a specific binary pattern See: instruction encoding click here

• This is what a machine (= computer) instruction would look like:

 ``` 11010100 10100010 00010001 11110000 ...... binary numbers ! ```

The computer uses these binary numbers to control its internal circuitry to execute the encoded instruction

• Machine instruction codes

• Machine codes (a.k.a. computer instruction codes):

• Each machine operation is uniquely represented by a binary number (= code)

• Sample machine operations are:

 Copy the value stored in a memory location to another memory location Add two values and store the sum in the destination Subtract two values and store the difference in the destination Jump to a certain location in computer (RAM) memory And so on....

• Computer program:

 Computer program = a sequence of machine instructions (codes)

• In the beginning: programming a computer in the pioneer days

• Fact:

 Program a computer = write a sequence of machine codes ( = binary numbers !!!) to tell the computer to do what you want

• How we program a computer in the pioneer days:

What you need to do is:

 Flip a row switches to ON/OFF to represent a row of 0/1 that represent the binary code for a computer instruction Then press store to store the instruction into the next computer memory Repeat the steps

• Observation:

 It's very tedious to write binary numbers (by flipping switches) !!!

• Important note:

• Machine instrucions are specific to a computer:

 Different computers use different binary numbers to encode (= represent) a given operation

Therefore:

 A program written in machine code can only be run (= executed) by one specific type of computer

• Next step in computer programming: Assembler programs

• Assembler instruction:

• Assembler instruction = a mnemonic code to represent a machine instruction:

 Each machine instruction corresponds to exactly one assembler instruction

• Assembler program:

• Assembler program = a program written in assembler instructions or assembler language

• An assembler language is also known as:

 The 2nd generation programming language

• Examples of assembler instructions:

 ``` move x, y ; copy data stored in memory location x to mem loc y add #1, y ; y = y + 1 ```

• Assembler programming:

 The programmer writes his/her program with assembler instructions using a text editor (e.g.: gedit)

• Assembler

• Assembler:

• Assembler = a computer program that translate the assembler instructions in an (low level) assembler program into (executable) machine instructions

Graphically:

• Note:

• There is a one-to-one correspondence between assembler instruction and machine instruction !!!

 One assembler instruction will translate to one machine instruction (= binary number) One machine instruction has one assembler instruction (nmemonic)

• Properties of assembler programming

• Assembler programming vs. machine language (binary) programming:

 Assembler programming was much easier to program than flipping swutches to code binary numbers !!!

However:

• Assembler programming was very closely related to machine language programming:

 There is an one-to-one correspondence between an assembler instruction and a machine instruction

• More importantly:

 An assembler programmer must have intimate understanding of the internals of the CPU before s/he can write an assembler program !!!

• Important note:

• Just like machine instrucions, assembler programs are also specific to a computer:

 Different computers use different assembler instructions to encode (= represent) a given operation

Therefore:

 A program written in assembler code can only be run (= executed) by one specific type of computer

• Assembler programming and CPU structure

• Fact:

 Assembler instructions (= machine instruction !!!) must use resources (registers !!!) inside the CPU (Central Processing Unit)

Therefore: when we learn assembler programming using M68000

 We will need to know the structure of the M68000 CPU

We will study the M68000 CPU soon...

• 3rd generation programming: high level programming language (compiler)

• High level programming language:

 High level programming language = a programming language that allows the programmer to express an algorithm without knowing the internal details of the computer used to execute the computer program

Sample high level programming languages:

 Java !!! C Python And so on (too many to mention)

• Compiler:

• Compiler = a computer program that translate the statements in a (high level) programming language into (executable) machine instructions

 One statement in a high level language usually translates into multiple (many) machine instructions !!!

Graphically:

• How a high level programming language program can be executed by different computers

• Key:

 For each computer, we must write a compiler that translate the high level language program to the assembler language of that machine

• How to achieve "machine independence" using a compiler:

• Suppose we have 2 different computers X and Y

• We want to run the same program on these computers

• How to execute the same program on the different computers: