3.4.4 Classification of programming languages and translators Flashcards
What are the instructions that tell a computer what to do written in?
What actually is this?
What does each ‘thing’ represent?
The instructions that tell a computer what to do are written in machine code.
Machine code is a series of numbers written in binary.
Each number represents a different instruction.
- How do programmers find machine code (to do 3 things)
- so what do they do
- and this way is good cos
Big chunk
Programmers find machine code difficult to learn, program in and debug.
As a result, the majority of programmers write programs in high-level programming languages.
These languages are close to natural language - the spoken and written language of humans.
For example, Python uses ‘print’, ‘if’, ‘input’ and ‘while’ statements - all words from the English language - to form instructions.
In fact, instructions often look like abbreviated English sentences.
Why do programmers write in high level languages? (2)
+ what do they allow
+ example
Programmers write in high-level languages because they are easier to understand and are less complex than machine code.
They allow the programmer to focus on what needs to be done, rather than on how the computer actually works.
For example, in many high-level languages, to place a message on the screen, a programmer would use the statement ‘print’. The programmer might not know how the computer actually generates the message. They just need to know how to use the ‘print’ statement.
Many types of high-level language exist and are in common use today, including:
(6)
- Python
- Java
- C++
- C#
- Visual Basic
- JavaScript
What’s source code
Source code is the term given to a set of instructions that are written in human readable programming language
What must happen to source code ?
Source code must be translated into machine code before a computer can understand and execute it.
Low level languages are what?
Low-level languages are languages that sit close to the computer’s instruction set. An instruction set is the set of instructions that the processor understands.
Two types of low-level language are:
Two types of low-level language are:
machine code
assembly language
So what’s machine code
Machine code is the set of instructions that a CPU understands directly and can act upon. A program written in machine code would consist of only 0s and 1s - binary.
Machine code disadvantages (2 kinda) + why
This is very difficult to write and debug. Even a very simple program could have thousands of 0s and 1s in it.
What’s assembly language
Assembly language sits between machine code and high-level language in terms of ease of use. While high-level languages use statements to form instructions, assembly language uses mnemonics - short abbreviations. Each mnemonic directly corresponds with a machine code instruction
Assembly language.
Here are some examples of mnemonics:
Mnemonic Action
LDA Loads a value from a memory address
STA Stores a value in a memory address
ADD Adds the value held in a memory address to the value held in the accumulator
SUB Subtracts from the accumulator the value held in a memory address
MOV Moves the contents of one memory address to another
Adv of assembly languages
In assembly language, programmers write programs as a series of mnemonics. Mnemonics are much easier to understand and debug than machine code, giving programmers a simpler way of directly controlling a computer
Why are mnemonics easier for programmers
Writing in mnemonics is easy for programmers because they are usually brief representations of the actual commands. They are quicker to write than binary, and it is easier to spot mistakes.
Many machine code and assembly instructions contain two parts
Many machine code and assembly instructions contain two parts:
the opcode - this is the actual instruction
the operand - this is a value that the instruction uses or manipulates
Consider this set of program instructions:
Assembly language Opcode Operand Instruction
INP 1001 00000000 Input a number
STR 6 0011 00000110 Store it in address 06
LDR A1 0101 10100001 Load data from address A1
ADD #10 0010 00001010 Add the number 10 to the loaded address