Skip to content

Assembly Language Programming

Assembly Language Programming

Machine code instructions

Machine code instruction: a binary code with a defined number of bits that comprises an opcode and, most often, one operand. The only language that the CPU recognizes is machine code. Therefore, when a program is running and instruction is fetched from memory this has to be in the format of a binary code that matches the specific machine code that the CPU uses.

Assembly language

The essence of assembly language is that for each machine code instruction there is an equivalent assembly language instruction which comprises:

• a mnemonic (a symbolic abbreviation) for the opcode

• a character representation for the operand.

If a program has been written in assembly language it has to be translated into machine code before it can be executed by the processor. The translation program is called an ‘assembler’

Directive: an instruction to the assembler program

Directives and system calls are instructions to the assembler as to how it should construct the final executable machine code. They can involve directing how memory should be used or defining files or procedures that will be used. They do not have to be converted into binary code.

Addressing modes When an instruction requires a value to be loaded into a register there are different ways of identifying the value. These different ways are described as the ‘addressing modes’.

Assembly language instructions

Data movement

These types of instruction can involve loading data into a register or storing data in memory. The diagram below contains a few examples of the format of the instructions with explanations. It should be understood that an actual instance of an instruction would have an actual address where is shown, a register abbreviation where is shown and a denary value for n where #n is shown. The explanations use ACC to indicate the accumulator.

Comparisons and jumps

A program might require an unconditional jump or might only need a jump if a condition is met. In the latter case, a compare instruction is executed first and the result of the comparison is recorded by a flag in the status register. The execution of the conditional jump instruction begins by checking whether or not the flag bit has been set.

Input and output

The two examples here are instructions for a single character to be input or output. In each case the instruction has only an opcode; there is no operand:

• The instruction with opcode IN is used to store in the ACC the ASC II value of a character typed at the keyboard.

• The instruction with opcode OUT is used to display on the screen the character for which the ASC II code is stored in the ACC