ScholaFly

CS06-06 Computer Science Watch

Machine code and assembly language

Watch on YouTube

In this lesson

How to explain the differences between machine code and assembly language - machine code, with worked examples and the mistakes examiners report. AQA 8525 and Edexcel 1CP2 GCSE. Software and languages 6 of 8. Full Software and languages playlist: https://www.youtube.com/playlist?list=PLQW0s9-KegDg More at https://scholafly.com

By the end: Explain the differences between machine code and assembly language - machine code is binary instructions the processor executes directly, specific to a processor or family; assembly language uses mnemonics, has a one-to-one correspondence with machine code and must be translated by an assembler - and say what assembly language is used for.

What it covers

  1. 0:00 Intro: machine code and assembly language
  2. 0:48 The language ladder
  3. 4:01 Assembly language
  4. 8:12 Telling them apart

Key words

About this video

Machine code and assembly language | GCSE Computer Science | CS06-06

How to explain the differences between machine code and assembly language - machine code, with worked examples and the mistakes examiners report.
AQA 8525 and Edexcel 1CP2 GCSE. Software and languages 6 of 8.
Full Software and languages playlist: https://www.youtube.com/playlist?list=PLQW0s9-KegDg
More at https://scholafly.com

Video code: CS06-06 (search "ScholaFly CS06-06")

#GCSEComputerScience #SoftwareAndLanguages

For teachers
This GCSE Computer Science lesson teaches machine code and assembly language. By the end, students should be able to explain the differences between machine code and assembly language - machine code is binary instructions the processor executes directly, specific to a processor or family; assembly language uses mnemonics, has a one-to-one correspondence with machine code and must be translated by an assembler - and say what assembly language is used for. It works through four worked examples and the mistakes examiners report.

Exam board specification references:
AQA 8525
- 3.4.4
Edexcel 1CP2
- 3.3.1

Read the transcript

Why would a programmer ever write the word add, when the processor can only run ones and zeros? The first people to program electronic computers had no words to use at all. They entered every instruction as a row of ones and zeros, and one wrong digit made it a different instruction. The tempting answer is that a word lets the computer understand the code. It does not, because the processor never sees the word at all. The words are for someone else, and something turns them back into ones and zeros.

Picture the language ladder, with the person at the top and the processor at the bottom. This video stays on its bottom two rungs: machine code, and assembly language just above it. Both rungs are low-level languages, meaning languages close to the processor's own instructions. If that idea is new, the video on high-level and low-level languages builds the ladder from the start. Not every exam board asks for this one. Check your own course: if it is not on yours, it still makes the next video easier to follow. Start on the bottom rung. Machine code is instructions written in binary, the ones and zeros, that the processor can execute directly, meaning it carries them out with no translation. Each type of processor has its own instruction set, the full list of instructions it can carry out, each with its own binary pattern. That makes machine code specific to one processor or family of processors. One more word before a question. A compiler is one kind of translator, a program that turns a whole high-level program into machine code. Try this one. Which two of these are true of machine code? A, it is executed directly by the processor. B, it is easily understood by humans. C, it is translated by a compiler. D, it is specific to a family of processors. A and D are true. Machine code runs with no translation, and it belongs to one processor family. B is false, because rows of binary are very hard for a person to read. Now the reason. Why is C, translated by a compiler, wrong? A compiler produces machine code. Nothing translates machine code, because the processor runs it directly. Every translator points into the bottom rung of the ladder, and none leads out of it. One examiner's report on a question like this says it was generally well answered, though a considerable number of students thought machine code is translated using a compiler. The fix is to treat machine code as the place where translation ends. Translators make machine code, and the processor runs it.

Now the rung above. Writing rows of binary by hand is slow, and one wrong digit changes the instruction, which is why programmers gave each binary instruction a short name. Those names are mnemonics. A mnemonic is a short code word that stands for one machine code instruction, such as load, add or store. The word is spelt with a silent M at the start. Assembly language is a low-level language that uses mnemonics in place of binary instructions. Take one line, load a number. It stands for one row of binary, one machine code instruction, and the same holds for every line of assembly. That is called a one-to-one correspondence: each assembly language instruction translates into one machine code instruction. A high-level language works differently, because one of its statements usually becomes many machine code instructions. Now a prediction. Each line of assembly becomes one machine code instruction. Is assembly language portable, like a high-level language, or tied to one processor? It is tied to one processor or family, because each mnemonic stands for one of that processor's own instructions. Move the program to a different type of processor, and the assembly has to be rewritten for that processor's instructions. The processor still cannot run the mnemonics themselves. Assembly language must be translated into machine code before it runs, and the translator that does it is an assembler, a program that turns assembly language into machine code. How an assembler compares with the other translators is the job of the video on compilers, interpreters and assemblers. That means a mnemonic is there for the person. The processor never sees it, and only ever executes the binary the assembler produces. One examiner's report notes a common misconception: that low-level programming languages allow a computer to understand the code. The fix is in the verb. A processor executes instructions, and it executes only machine code. Write executes, and never understands. Now a counting question. A short assembly program has three lines: load a number, add another number, store the result. How many machine code instructions will it become, and what translates it? Three, one for each line, because assembly has a one-to-one correspondence with machine code. An assembler does the translating. Assembly language is used where a programmer needs direct control of specific hardware, such as software for embedded systems. Those are the small computers built into devices like microwaves and car engines. It is also chosen when code must be very small or very fast, because the programmer picks every instruction. The embedded systems video covers what those devices are.

Now the two rungs side by side. A difference is one property that sets them apart, stated for both. Machine code is written in binary, while assembly language uses mnemonics. Machine code runs directly, while assembly language must first be translated by an assembler. Machine code is very hard for a person to read and write, while assembly is easier, though still far harder than a high-level language. Some things are true of both, so they are not differences. Both are low level, and both are specific to one processor or family. A question asks for two differences between assembly language and machine code, and the second must not be the reverse of the first. A student writes: machine code is in binary, and assembly language is not in binary. A different kind of question now. Has the student given one difference or two? Only one difference. Its two halves make a single point, said once each way round. One examiner's report, on a question asking how these two languages differ, says just over seventy per cent of students were able to gain one or two marks. It adds that a common error was writing one difference and then the converse of that difference. The converse means the same point turned round, and the report says it could not be awarded the second mark. The fix is to make your second difference about a different property. Binary against mnemonics is one difference. Runs directly against needs an assembler is another. Some questions ask for characteristics instead. A characteristic is what assembly language is like. An advantage or a drawback is what that makes it good or bad for. One more choice to make. Which two of these are characteristics of assembly language: it uses mnemonics; it is hard to debug; each line becomes one machine code instruction; it is slow to write? Uses mnemonics, and each line becomes one machine code instruction. Those describe what the language is. Being hard to debug and slow to write are what it is bad for, so they are drawbacks. One examiner's report says some candidates confused characteristics with benefits and drawbacks, and gave responses comparing assembly language with a high-level language. The fix is to describe the language itself. Uses mnemonics, one-to-one with machine code, and specific to one processor's architecture, meaning its design, are all characteristics. Now a written one. Have a go at this one before I show you: give one advantage of programming in assembly language, and say why it is not a characteristic. It can run fast and use little memory, because the programmer chooses every instruction. That is what the language is good for, not what the language is, so it is an advantage.

Time to check what has stuck, four questions to finish.

First, what translates assembly language, and how many machine code instructions does one line of assembly become? An assembler, and one, because assembly has a one-to-one correspondence with machine code.

Now the second. A student writes that machine code is translated by a compiler. What should it say instead? Machine code is not translated at all. The processor executes it directly, and a compiler is one of the things that produces it.

Now a new case. A programmer writes six lines of assembly for one processor. How many machine code instructions is that, and will they run on a processor from a different family? Six instructions, one per line. They will not run on the other family, because machine code is specific to one processor or family.

Now the final one. Can you give one characteristic of assembly language that is not an advantage? It uses mnemonics. Each line translating into one machine code instruction, or being specific to one processor's architecture, would also do.

So names such as add, which those first programmers gave their binary instructions, were mnemonics, written for the person. An assembler turns each one into one machine code instruction, and the processor runs only the binary.

If that's in the bag, give it a thumbs-up. If that felt fast, that's normal: the bottom of the ladder is dense, and a second look settles it.

Next in the chapter is Compilers, interpreters and assemblers. Hopefully that's next in your feed, but if not, search for ScholaFly C S oh six, oh seven.

Every other video is on scholafly.com too, easy to search by video code or by keyword. Whatever you're revising, go there and have a look, or, watch the next video.

Related terms

For: AQA GCSE 8525, Edexcel GCSE 1CP2

On the specification

BoardSpecStatement
AQA GCSE 85253.4.4Classification of programming languages and translators
Edexcel GCSE 1CP23.3.1Explain the characteristics and purposes of low-level and high-level programming languages.
For teachers

This GCSE Computer Science lesson teaches machine code and assembly language. By the end, students should be able to explain the differences between machine code and assembly language - machine code is binary instructions the processor executes directly, specific to a processor or family; assembly language uses mnemonics, has a one-to-one correspondence with machine code and must be translated by an assembler - and say what assembly language is used for. It works through four worked examples and the mistakes examiners report.