44 total
By the end of this subtopic, you should be able to:
explain the relationship between assembly language and machine code
describe the stages of the two-pass assembler process
apply the two-pass assembler process to a simple assembly language program
trace a simple assembly language program step by step
understand that assembly language instructions are grouped into:
understand and use different addressing modes, including:
A computer’s CPU can only understand machine code. Machine code is the computer’s own language. It is made up of binary, which means patterns of 0s and 1s.
This is important: no matter what language a program was first written in, the CPU can only run it after it has been turned into machine code.
Machine code is hard for humans to read and write. It is very easy to make mistakes because the instructions look like numbers rather than meaningful words. Testing a machine code program is also difficult, because errors are not easy to spot by just looking at the code.
To make programming easier, assembly language was developed. Assembly language is still a low-level language, which means it is very close to machine code. However, instead of long binary patterns, it uses short readable instruction names called mnemonics.
For example:
These mnemonics are much easier for a person to understand than binary.
Assembly language and machine code match very closely. In fact, each assembly language instruction usually translates into one machine code instruction.
Both forms have the same basic structure:
The opcode tells the CPU what action to perform.
The operand tells the CPU what data or address to use.
For example:
LDD Total
In the assembly language version, the operand may be written as a label such as Total. After translation, that label is replaced with an actual memory address in machine code.
So the key relationship is this:
Different CPUs do not all use the same instruction set. An instruction set is the complete list of instructions a CPU can understand.
That means assembly language is machine-specific or chip-specific. A program written for one type of CPU may not work on another CPU if they use different instruction sets.
So assembly language is easier than machine code for humans, but it is still closely tied to a particular processor.
Before an assembly language program can run, it must be translated into machine code. This translation is done by a program called an assembler.
The assembly language program before translation is called the source code.
The translated machine code program is called the object code or object program.
An assembler also checks that the program uses valid instructions. For example, it checks whether the opcodes are part of the correct instruction set. This helps find some errors before the program is run.
There are two main types of assembler:
A one-pass assembler goes through the source code once and places the machine code straight into memory for execution.
A two-pass assembler goes through the source code twice. It creates an object program that can be stored and loaded later. A separate program called a loader is then used to place the object code into memory before execution.
For this syllabus, the important one is the two-pass assembler.
Sign in to view full notes