Assembly language

Assembly languages use mnemonics to represent opcodes. In an exam you would be provided with the assembly language codes below and be expected to either interpret assembly language programs, complete trace tables for them based on certain inputs or even write short assembly language programs.

A # before an operand means immediate addressing should be used
An R means direct addressing should be used

Load and store

Values that are going to be used in calculations need to be loaded into the registers. Results of calculations need to be stored back to memory locations.
LDR R0, 00001100 means load the value in memory location 12 into register 0
STR R1, 3 means store the value of register 1 into memory location 3
You may see memory addresses and operands as either binary or decimal values but always remember that it is binary values stored in memory locations and binary values used to address memory.

Add and subtract

The first value specified in these commands is where to store the result. The first value used in an add or subtract command must be held in a register. The value you add or subtract to or from it can either be an actual value or the value stored in a register.
ADD R0, R0, R0 would mean add the value stored in register 0 to itself and store it back in register 0 effectively doubling its value
SUB R1, R0, #00000101 would mean subtract 5 from the value in register 0 and store the result in register 1

Move and compare

Move puts the value of a register or an actual value in a specified register. It is important to note that though the name implies the value is moved it is actually copied and remains in the location it was moved from as well as the one it is moved to.
Compare compares the value in a specified register with an actual value or the value of a register. This allows for a branch condition to be checked on the next line depending on whether the value in the register specified is equal, unequal, greater or less than the value specified by the operand.
MOV R0, #5 would mean put the actual value 5 into Register 0,MOV R0, R5 would mean put the value from register 5 in register 0
CMP R0, R1 would compare the values in R0 and R1 so you can check with a branch condition

Branching

Branching is where a command specifies a non sequential line to move the execution to. This might be a branch always or a conditional branch based on the result of a comparison. In this case it may branch if the comparison showed two values were equal, inequal or greater than or less than each other. Labels are inserted into the code at the point where the program will recommence after a branch. In some cases labels will be on their own line as in the example below and sometimes they may be shown on the same line as the line you branch to e.g. END: STR R2, 103.

Logical AND and OR

Values stored in registers are stored in binary. These operations perform a logical AND or OR, between the binary value in a register and the binary value in a register or provided as an immediate value

Logical EOR and NOT

An EOR is an exclusive or and is between the value in a register and an operand. A NOT reverses the value of an operand.

Bit shifts

LSL and LSR stand for logical shift left and logical shift right which means shift the bits.
LSL R1, R0, #1 would mean shift the value in register 0 left by one place effectively doubling it and store the result in register 1
LSR R0, R0, R1 would mean shift the value in register 0 right the number of times specified in register 1 and store the result back in register 0

Knowledge check


Questions:
Correct:

Question text


© All materials created by and copyright S.Goff