A-level Computing/AQA/Paper 2/Fundamentals of computer organisation and architecture/Machine-code/assembly language operations





Machine code
As we should hopefully already know, computers can only understand binary, 1s and 0s. We are now going to look at the simplest instructions that we can give a computer. This is called machine code.

Machine code allows computers to perform the most basic, but essential tasks. For this section we are going to use the Accumulator (you met this register earlier) to store the intermediate results of all our calculations. Amongst others, the following instructions are important for all processors: Assembly code is the easy to read interpretation of machine code, there is a one to one matching, one line of assembly equals one line of machine code: Let's take a look at a quick coding example using assembly code. The code above is the equivalent of saying  in VB.NET.
 * LDA - Loads the contents of the memory address or integer into the accumulator
 * ADD - Adds the contents of the memory address or integer to the accumulator
 * STO - Stores the contents of the accumulator into the addressed location

Instruction set
There are many different instructions that we can use in machine code, you have already met three (LDA, ADD, STO), but some processors will be capable of understanding many more. The selection of instructions that a machine can understand is called the instruction set. Below are a list of some other instructions that might be used: Let us look at a more complex example of assembly code instructions: You'll notice that in general instructions have two main parts: Depending on the word size, there will be different numbers of bits available for the opcode and for the operand. There are two different philosophies at play, with some processors choosing to have lots of different instructions and a smaller operand (Intel, AMD) and others choosing to have less instructions and more space for the operand (ARM).
 * opcode - instruction name
 * operand - data or address
 * CISC - Complex Instruction Set Computer - more instructions allowing for complex tasks to be executed, but range and precision of the operand is reduced.  Some instruction  may be of variable length, for example taking extra words (or bytes) to address full memory addresses, load full data values or just expand the available instructions.
 * RISC - Reduced Instruction Set Computer - less instructions allowing for larger and higher precision operands.

Addressing modes
You might notice that some instructions use a # and others don't, you might even have an inkling as to what the difference is. Well here is the truth: # = number [no hash] = address Let's take a look at a quick example: Let's take a look at doing this without the hashes: {| class="wikitable" ! Assembly code !! Main memory start !! Main memory end


 * colspan="3" | This code loads the value stored in memory location 10 into the accumulator (9), then adds the value stored in memory location 12 (7), it then stores the result into memory location 12 (9 + 7 = 16).
 * }
 * colspan="3" | This code loads the value stored in memory location 10 into the accumulator (9), then adds the value stored in memory location 12 (7), it then stores the result into memory location 12 (9 + 7 = 16).
 * }

There are many types of addressing modes. But we only need to know 3, they are:

Machine code and instruction sets
There is no set binary bit pattern for different opcodes in an instruction set. Different processors will use different patterns, but sometimes it might be the case that you are given certain bit patterns that represent different opcodes. You will then be asked to write machine code instructions using them. Below is an example of bit patterns that might represent certain instructions.

If you would like to play around with Assembly language a great place to start is the Little man computer. You can find a Java applet and some examples at the York University website or a javascript version created by Peter Higginson