1.4.3 The Processor's Instruction Set
1.4.3 The Processor's Instruction Set
1.4.3 The Processor's Instruction Set
Page 1 of 8
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). Know it now and we will study it in detail in paper 3.
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.
Page 2 of 8
Immediate Addressing
Immediate addressing means that the data to be used is hard-coded into the instruction itself.
15T
This is the fastest method of addressing as it does not involve main memory at all.
For example, you want to add 2 to the content of the accumulator
The instruction is:
LDM #2
Nothing has been fetched from memory; the instruction simply loads 2 to the accumulator
immediately.
Immediate Addressing is very useful to carry out instructions involving constants (as opposed to
variables). For example you might want to use 'PI' as a constant 3.14 within your code.
Page 3 of 8
In this instance the value held at the direct location 3001 in RAM is loaded to the accumulator.
The good thing about direct addressing is that it is fast (but not as fast as immediate addressing)
the bad thing about direct addressing is that the code depends on the correct data always being
present at same location.
It is generally a good idea to avoid referring to direct memory addresses in order to have 'relocatable code' i.e. code that does not depend on specific locations in memory.
39T
39T
You could use direct addressing on computers that are only running a single program. For
example an engine management computer only ever runs the code the car engineers
programmed into it, and so direct memory addressing is excellent for fast memory access.
Indirect Addressing
Indirect addressing means that the address of the data is held in an intermediate location so that
the address is first 'looked up' and then used to locate the data itself.
15T
Many programs make use of software libraries that get loaded into memory at run time by the
loader. The loader will most likely place the library in a different memory location each time.
So how does a programmer access the subroutines within the library if he does not know the
starting address of each routine?
Answer: Indirect Addressing
Page 4 of 8
39T
2. In order for the CPU to get to the data, the code first of all fetches the content at RAM location
5002 which is part of the vector table.
3. The data it contains is then used as the address of the data to be fetched, in this case the data
is at location 9000
A typical assembly language instruction would look like
LDI 5002
This looks to location 5002 for an address. That address is then used to fetch data and load it
into the accumulator. In this instance it is 302.
Page 5 of 8
39T
39T
39T
Index addressing is fast and is excellent for manipulating data structures such as arrays as all
you need to do is set up a base address then use the index in your code to access individual
elements.
Another advantage of indexed addressing is that if the array is re-located in memory at any point
then only the base address needs to be changed. The code making use of the index can remain
exactly the same.
Page 6 of 8
39T
DEFINITION:
39T
39T
Relative addressing means that the next instruction to be carried out is an offset
number of locations away, relative to the address of the current instruction.
Consider this bit of pseudo-code:
jump +3 if accumulator == 2
code executed if accumulator is NOT = 2
jmp +5 (unconditional relative jump to avoid the next line of code)
acc:
code executed if accumulator is = 2)
carryon:
In the code snippet above, the first line of code is checking to see if the accumulator has the
value of 2 in it. If it is has, then the next instruction is 3 lines away. This is called a conditional
jump and it is making use of relative addressing.
39T
39T
Another example of relative addressing can be seen in the jmp +5 instruction. This is telling the
CPU to effectively avoid the next instruction and go straight to the 'carryon' point; lets say
present at this address +5.
Page 7 of 8
Indexed
Addressing
Relative
Addressing
Memory modes
Comment
Apply a constant to the accumulator. No need to access main memory
This is a very simple way of addressing memory - the code refers directly to
a location in memory. Disadvantage is that it makes relocatable code more
difficult.
Looks to another location in memory for an address and then fetches the
data that is located at that address. Very handy of accessing in-memory
libraries whose starting address is not known before being loaded into
memory
Takes a base address and applies an offset to it and fetches the data at that
address. Excellent for handling data arrays
Tells the CPU to jump to an instruction that is a relative number of locations
away from the current one. Very efficient way of handling program jumps
and branching.
Page 8 of 8