Assembly Language
Last updated
Last updated
Computers can only process code that's written in machine code. As you know, machine code is composed of 0s and 1s, this makes machine code harder to work with. That's why programmers use assembly language, which uses mnemonics to represent operation codes (opcodes).
In a simple computer, all calculations are carried out in a single register called accumulator. However, some other computers use up to 16 general purpose registers to temporarily hold values whilst final result is being calculated. Usually, assembly instructions are unique to a given computer architecture. A group of instructions given for a specific computer is called an Instruction Set.
The <operand> can be:
The actual value (specified by #, to include binary number, you must add B at the end. e.g. #11B)
A value stored in a register (specified by R)
This instruction uses immediate addressing, as the actual value (5) is given in the operand:
Whereas this instruction uses direct addressing, as the operand contains memory address (300) of the data:
Comments can be added to the code by using a semi-colon so that you can explain to other programmers what the program is actually doing:
There are no IF statements in assembly language. Instead, compare and branch instructions are used for .
Loops also don't exist in assembly language. So in order to do , we need compare and branch instructions.
The program above keeps on repeating until the user inputs the number 5.
Instructions to perform AND, OR, NOT and XOR operations typically look like this:
Left Logical Shift: Multiplies the number by 2 for one shift. Use the Instruction LSL Rd, Rd, <operand>
Right Logical Shift: Divides the number by 2 for one shift. Use the Instruction LSL Rd, Rd, <operand>
The <operand> is the number of bits that the number will be shifted by.
Visual Assembler: