Machine code is the language computers can understand so all other languages must be converted to machine code
A machine code instruction usually consists of 2 parts - the opcode and the operand
Sometimes there can be no operand or sometimes more than one operand
This is done by sending it to the Control unit
We will look at this notation again
CU ← [CIR[x:y]]This shows that part of the instruction stored in the CIR is sent to the CU and this is the opcode
As it is hard to code in machine code we use assembly language as this makes it easier to read and code and so less errors
Also it executes much faster compare to high level languages as assembly language is considered as a low level language
So an assembler is required to convert the assembly language to machine code(binary)
Programs written in assembly language uses Mnemonics to represent opcodes - example ADD and SUB
The use symbolic names for the operands - example TOTAL
Usually a code written in assembly language will have:
1. Comments
2. Directives
3. Mnemonics
4. Labels(operand)
5. Macros
All of this must be converted or adjusted to machine code using an assembler.
Instructions given to the assembler on how to translate the code and produce the final code. Also it defines any use of files or procedure to be used by the code
A sequence of instruction or a block of code which is used frequently - this is like a procedure
There are 3 ways assembly language program can be written in and they are:
So this uses labels or symbolic names to represent the addresses
Example is ADD NUMBER
The NUMBER is an identifier which stores a particular value in that address
So this uses offset values to represent the addresses. This means that the operand is represent as an offset value from the starting point or the base address.
Example is ADD [BR] + 15
This shows that the address to be used is 15 steps away(down) from a defined base address.
It uses the actual address for the operand
Example is ADD 200
It is either the starting address or the address defined so all other addresses are offset values from it. Offset values - It shows the number of steps away the address is from the base address.
We will need to know the steps and points when an assembly language program is translated. Also as we usually use symbolic addressing we must also convert the labels for the operand to offset values.
This is why there are 2 steps for this translator.
So these must be done before the translation.
The assembler will remove any macros names and replace it with the block of code. Also any directives are removed and stored for later use. The comments are also removed.
During the translation
The First pass of the assembler - converts the symbolic names or labels to their offset values.
This is done by using a symbol table which contains the symbol names and there corresponding offset values
The second pass of the assembler - converts the opcode to the corresponding machine code using the processors instruction set
This at last converts the assembly code to machine code which is an executable file
There are 4 types you need to know:
For example if we have LDM #34
This means that the value 34 is loaded to the ACC
Always remember if there is a #n or #Bn(binary) or #Hex then it is immediate addressing and the value of the operand is used
An example is ADD 100
An example is LDD 200
So in the address 200 there is a value of 500 which is actually another address and the value in 500 is used by the instruction
For example - LDX 100 means that 100 is added to the value in the Index register(300) so we get 400 and this is the address which contains the value
We have seen some of the opcodes such as ADD LDD LDM and more
We don't need to remember these as the exams always gives us the table
A point to remember is that the Mnemonics usually identifies both the action and the addressing mode - Example LDD is for direct addressing whereas LDM #n is for immediate addressing
There will be many Opcodes such as CMP and JMP and Bitwise operations. They will usually give the instruction set and explain each function
The reason why they give us these is to be able to trace the assembly language - meaning we need to update the values in the register such as ACC and the memory locations
Shifting means that the bits are shifted to one direction and the removed bit is replaced by a 0
There are 3 types of shifts we will need to know:
Logical shifts can either be left logical shifts(LSL #n) or right logical shifts(RLS #n)
This shifts the bits in the accumalator to the left or to the right
An example is the ACC contains 10101010 and this is shifted left by 2 (LSL #2) this will produce a new value in the ACC of 10101000
The bits are shifted in a cycle and it reappears on the other side of the register
Used for multiplication and division calculations where the sign doesn't change
We don't need to know these in depth but just have a basic understanding. Logical shifts are the most important thing to remember
We have discussed in chapter 1 that the CPU must be able to detect overflow errors and correct them. We will see a brief explanation.
Firstly you need to remember the status register and the 3 flags (overflow,carry and negative flag)
Negative flag(N) - checks whether the result is negative
Overflow flag(V) - checks whether the Most significant bit has been changed due to an overflow
Carry flag(C) - checks whether a positve value is caused but has been caused by an overflow
If the addition of two positive values results in a negative value - both the negative and overflow flag are set to true and so the processor must try to fix it depending on this combination of flags
If the addition of two negative values results in a positive value - both overflow and carry flags are set to true and the processor must be able to detect this and correct it.
The mechanism of correction is not required
This is always asked in past papers
They usually give us the instruction set which define what each opcode does.
The trace table holds the contents of the registers (Accumalator) and the memory address used to store values
You need to know some points when doing the trace table, you need a new line for each instruction in the trace table
Also the value must be recorded only when the value is updated or else you could leave it blank
Check the video section to see an example on this
These are things you might like. Clicking these ads can help us improve our free services in the future...