Uses mnemonic to represent the operation codes. There are different assembly languages for each different type of processor. The assembler translates the assembly language program into machine code for execution.
The Little Man Computer
An imaginary computer with a very limited instruction set.
ADD = ADD (add the contents of the memory address xx to the accumulator)
SUB = SUBTRACT (subtract the contents of the memory address xx from the accumulator)
STA = STORE (store the value in the accumulator in the memory address xx)
LDA = LOAD (load the accumulator with the contents of the memory address xx)
LMC Example
INP *wait for the user to input data*
STA num1 *store the number input by the user in num1*
INP *wait for user to input data*
ADD num1 *add num1 to the value in the accumulator*
OUT *output the contents of the accumulator*
num1 DAT
If the user inputs the numbers 10 and 3 the output would be:
13
The Little Man Computer
Data can be entered by a user and stored in memory. Variables are shown with a DAT statement. All calculations are carried out in the accumulator. An output statement displays the contents of the accumulator.
The Instruction Set
The LMC has only 11 instructions, and the imaginary computer on which it runs has only 100 memory locations. On a real computer, there will be many more instructions
multiply and divide instructions
shift left and shift right instructions
Other useful instructions would be branch if not equal and branch if negative etc..
A typical machine code instruction, held in 16 bits could have 6 bits of basic machine operation followed by a 2 bit addressing mode which is followed by a further 8 bits.
Addressing Modes
The last 2 bits of the operation code (opcode) specify the addressing mode. This specifies whether the operand represents:
an actual value to be used in a calculation
the memory address of a value to be used
the address of a register or memory location which holds the memory address of the value to be used
an index
What are the 3 different addressing modes?
-Immediate Addressing
the operand holds an actual value
-Direct Addressing
the operand holds the address of the value
-Indirect Addressing
the operand is the location holding the address of the value
The LMC uses only direct addressing. You cannot load a value straight into the accumulator.
Indexed Addressing
Using indexed addressing, the address of the operand is obtained by adding a constant value to the contents of a general register (index register). Indexed addressing mode is use to access an array whose elements are in successive memory locations. By incrementing the value in the index register, successive memory locations can be accessed.
What are the advantages of indexed addressing?
-You can access many more than 255 memory locations
-A memory location of 16 bits can hold an address of 2^16-1=65,535 rather than just 255
-So by specifying that location 200, for example, holds the address of the data that you want, you can look in location 200 and find, for example, 60000, which is where the data is held