Course 4.3Lesson 1 of 3
A processor runs machine code, which is binary. Low-level languages are machine code and assembly language, which uses mnemonics and needs an assembler. High-level languages are closer to English and work on many machines, but cannot work the hardware directly. You compare them and learn the advantages of each.
Try the code and the simulations beside the lesson.
A processor understands one thing: machine code. Machine code is a list of instructions in binary, such as 0010 1111. Each kind of processor has its own set of instructions. Writing a long program as rows of 0s and 1s would be slow, and it is very easy to make a mistake.
So programmers write in other languages, and a translator turns their code into machine code. There are two levels of language.
A low-level language is close to the machine code of the processor. Machine code itself is low level. So is assembly language.
Assembly language uses mnemonics: short words that are easy to remember, such as LDA for "load" and ADD for "add". Each line usually matches one machine code instruction. An assembler is the translator that turns an assembly language program into machine code.
The example below uses a made-up assembly language for a processor with one register, the accumulator, which holds the number being worked on. Real processors have their own mnemonics. The exam does not ask you to learn any set of them.
LDA 14 loads the value at memory address 14 into the accumulator.ADD 15 adds the value at address 15 to the accumulator.STO 13 stores the accumulator at address 13.LDA 14 // load the value at address 14
ADD 15 // add the value at address 15
STO 13 // store the result at address 13The assembler turns each line into 8 bits: 4 bits for the operation and 4 bits for the address. Address 14 is 1110 in binary.
0001 1110
0010 1111
0100 1101A high-level language is closer to English and to mathematics. It uses words such as IF, WHILE and OUTPUT, and one statement can stand for many machine code instructions. Python is a high-level language. So is the pseudocode of the exam. Here is the same addition in Cambridge pseudocode. Pseudocode is shown, not run.
// Add two prices and output the total
Price1 ← 4
Price2 ← 6
Total ← Price1 + Price2
OUTPUT "Total: ", TotalAnd here it is in Python, in a box you can run.
A high-level program must be translated by a compiler or an interpreter before the processor can run it. That is the next lesson.
The syllabus compares the two levels in four ways.
Because low-level code works the hardware directly, it can also be made to run fast and use little memory. That is why parts of device drivers and small embedded systems are written in a low-level language.
The program is a tiny assembler and processor. It turns each line of the assembly program into machine code, then runs the program and prints the accumulator after each line.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
LDA 15, SUB 14, STO 13?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.