Computer Languages Machine language A collection of binary
Computer Languages • Machine language – A collection of binary instructions understood by a given type of CPU – Non-standard; low-level of detail related to the given hardware – Very hard to understand by human programmers – In order to be executed, any program must have been previously translated into machine language. • Assembly language – Mirrors closely a given machine language, only more readable by humans: uses mnemonics for instruction codes and names for variables • High-level languages – Closer to the human way of expression, using higher-level of abstraction concepts from the application area for which it is intended – Mostly standardized, thus independent of a given hardware. Algoritmos y Programacion 1 – The downside: computers do. JMHL not understand high-level languages. 1
Example: Adding two numbers together Suppose the two numbers we want to add are stored in memory locations 137 and 138, and we want to store the result in memory location 139. The following instructions need to be executed by the CPU: 1. Fetch the contents of memory location 137 and store it in a register in the ALU 2. Fetch the contents of memory location 138 and add it to the contents of the register 3. Store the contents of the register in memory location 139 Algoritmos y Programacion JMHL 2 2
Example: Adding two numbers together The machine language code to do this is: 1. 00110101 10001001 00000001 2. 10010101 10001010 00000001 3. 01000010 00000001 10001011 opcodes operands Algoritmos y Programacion JMHL 3 3
Example: Adding two numbers together The assembly language code to do this is: 1. LOAD $137, R 1 2. ADD $138, R 1 3. STORE R 1, $139 With assembly language it is also possible to assign labels to memory locations. If A is a label for location 137, B is a label for location 138, and C is a label for location 139, the assembly language code can be written as 1. LOAD A, R 1 2. ADD B, R 1 3. STORE R 1, C Algoritmos y Programacion JMHL 4 4
Example: Adding two numbers together High-level languages were developed to simplify programming. To add two numbers in C++, the programmer uses the expression c = a + b; Similar expressions are used in other programming languages • • • FORTRAN C=A+B APL C A+B COBOL ADD A TO B GIVING C. Algoritmos y Programacion JMHL 5 5
High-Level Languages Algoritmos y Programacion JMHL 6 6
- Slides: 6