Home Chemistry Physics HTML
Night More

Revise Now

GCE Subjects

Physics Chemistry CS Accounting

Coding Lessons

Learn HTML Learn SEO


What do you want
to do?

Contact us Support

more topic chapters

Assembly Language, Machine Code & Computer Arithmetics

Machine code instructions

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


It is the action to be taken by the instruction

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


It is the data or value to be used or needed by the instruction

Assembly Language

It is a low level language where opcodes are written using mnemonics and operand as labels/names

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)

Assembly language programs

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:


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

Representations of Assembly Languages

There are 3 ways assembly language program can be written in and they are:

  • Symbolic addressing
  • 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

  • Relatively addressing
  • 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.

  • Absolute addressing
  • It uses the actual address for the operand

    Example is ADD 200

    Base address

    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.

    Two pass assembler

    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

    Addressing mode

    It defines how the operand is to be used to obtain the value or data

    There are 4 types you need to know:

    • Immediate
    • The Operand is the value to be used by the instruction.

      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

    • Direct addressing
    • The operand is the address which contains the value to be used by the instruction

      An example is ADD 100

    • Indirect addressing
    • The operand is the address which contains a address which has the value to be used by the instruction

      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

    • Indexed addressing
    • The value of the operand is added to the contents of the Index register to form the address which contains the value

      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

    Assembly language instructions

    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

    Shift operations

    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
    • 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

    • Cyclic shifts
    • The bits are shifted in a cycle and it reappears on the other side of the register

    • Arithmetical shifts
    • 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

    Computer Arithmetics

    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...

    End of Chapter Questions
    Collection of Topic Questions to understand the topic more.

    Try out

    End of Chapter Videos
    Collection of Videos to Support Your Understanding.

    Remember these videos are handpicked by me and I feel these are one of the best ones out there. But I constantly update this list for each chapter.The Youtubers are more than welcome to contact me.

    Also, don't forget to Subscribe to our Youtube channel - Wiscus