Assembly Language and Instruction Groups
Assembly language represents processor instructions with short names called mnemonics. This is easier for a programmer to read than machine code. An assembler translates assembly-language source into machine code, also called object code in this context.
By the end of this page, you should be able to:
- explain the relationship between assembly language, an assembler and machine code;
- identify a label, opcode and operand in an instruction;
- classify instructions by their purpose;
- explain the roles of
IN,OUTandEND.
1. Assembly language is translated into machine code
Machine code is represented in binary and can be executed directly by the processor.
Assembly language uses readable mnemonic opcodes, such as ADD, to represent
instructions for a particular processor's instruction set.
The programmer writes assembly-language source code. The assembler translates that source into machine code. The translated machine-code program is the object code that the processor executes.
Keep the language and translator separate
Assembly language is the source. The assembler is the program that translates it. Machine code is the translated form that the processor can execute directly.
2. Read the parts of an instruction
An assembly-language instruction can contain a label, an opcode and an operand. A label is optional; the opcode is required.
CYCLE_BACK: JPN INTAKE
| Part | Example in the line | Purpose |
|---|---|---|
| Label | RETRY: |
A name for an instruction location. A jump instruction can use the name to refer to that location. |
| Opcode | JPN |
The mnemonic that identifies the operation the processor should perform. |
| Operand | INTAKE |
The information used by the operation, such as a value, register or address. |
The opcode is only the operation name, not the whole line. Some instructions in this instruction set,
including IN, OUT and END, do not have an operand.
3. Data movement and input/output
Instructions can be grouped by their function. Data-movement instructions load, store or move data between registers and memory. Input/output instructions communicate with the user or a device.
| Group or instruction | Purpose | Examples |
|---|---|---|
| Data movement | Load, store or move data between registers and memory. | LDM, STO, MOV |
| Input: IN | Accepts a typed character and stores its ASCII value in the ACC. | IN |
| Output: OUT | Outputs the character represented by the ASCII value in the ACC. | OUT |
IN receives a character; OUT
sends a character to an output device.
4. Arithmetic, compare and jump instructions
| Group | What it does | Examples |
|---|---|---|
| Arithmetic | Performs a calculation or increases/decreases a register by one. | ADD, SUB, INC, DEC |
| Compare | Compares the ACC with a value or memory contents. The comparison result can be used by a conditional jump. | CMP, CMI |
| Unconditional jump | Changes which instruction address is used next without checking a comparison result. | JMP |
| Conditional jump | Changes the next instruction address only when the stated comparison condition is met. | JPE, JPN |
JMP is unconditional: it transfers control to its target every time it runs. JPE
jumps when the comparison is true, while JPN jumps when the comparison is false.
A compare and a jump have different jobs
A compare instruction checks a relationship between values. A jump instruction changes which instruction is processed next. A conditional jump uses the result of a comparison.
5. END finishes the program
END ends the program and returns control to the operating system. It is not an input or
output instruction, and it has no operand in this instruction set.
IN and OUT are input/output;
END ends the program; ADD is arithmetic; CMP compares; and jump
opcodes change the next instruction address.
Interactive: inspect assembly instructions
Work through the instruction cards. Some ask you to identify a label, opcode or operand; others ask you to classify the instruction's function. The lines use fresh symbolic names and do not require you to trace or execute a program.
6. Avoid these common mix-ups
| Mix-up | Keep the ideas separate |
|---|---|
| Calling the assembler “assembly language” | Assembly language is the source. The assembler is the translator. |
| Calling the whole line the opcode | The opcode is the mnemonic operation name. A label and operand are separate parts. |
Calling END an output instruction |
END ends the program and returns control to the operating system. |
| Calling every jump unconditional | JMP is unconditional. JPE and JPN depend on the comparison result. |
Calling CMP a jump |
CMP compares values; a conditional jump can then use the comparison result. |
7. Check your understanding
Answer each question before opening the suggested response.
-
What does an assembler do?
Suggested response
It translates assembly-language source code into machine code, also called object code in this context.
-
In
CATALOG: STO ENTRY, identify the label, opcode and operand.Suggested response
Label:
ARCHIVE:; opcode:STO; operand:RECORD. -
Which instruction group contains
INCandDEC?Suggested response
Arithmetic instructions. They change a register by one.
-
Explain the difference between
JMPandJPE.Suggested response
JMPtransfers control without checking a comparison result.JPEtransfers control only when the comparison is true. -
What does
INdo, and what doesENDdo?Suggested response
INaccepts a typed character and stores its ASCII value in ACC.ENDfinishes the program and returns control to the operating system.
Final check
When asked to identify instruction parts, label each part separately. When asked to describe an instruction group, state its function and include a suitable opcode example.