Assembly language

Computer Science AS · Processor fundamentals. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science AS topics

The idea

Machine code is the binary code a processor runs directly. Assembly language writes the same instructions with short names (mnemonics) such as LDD and ADD, and with labels in place of addresses. Each assembly instruction has an opcode, which says what to do, and usually an operand. One assembly instruction normally becomes one machine code instruction.

An assembler does the translation. A two-pass assembler reads the program twice, so that a label can be used before the line where it is defined.

The addressing mode tells the processor how to use the operand: as the value itself, as an address, or as a way of working out an address.

In simpler words

Machine code is the binary a CPU runs. Assembly language writes the same instructions with short names like ADD and LDD, and labels instead of addresses. An assembler turns assembly into machine code. A two-pass assembler reads the program twice, so labels can be used before they are defined. The addressing mode tells the CPU how to use the number after the instruction.

An everyday comparison

Addressing modes are like instructions to find a parcel. Immediate: 'here is the parcel'. Direct: 'the parcel is in locker 60'. Indirect: 'locker 60 holds a note saying which locker has the parcel'. The comparison stops working because lockers do not change, while in indexed addressing the address used depends on the IX register's current contents, and relative addressing depends on where the current instruction is in memory.

Rules to remember

Common mistake

Students load the address in place of its contents. LDM #60 puts the number 60 in ACC, but LDD 60 puts the contents of address 60 in ACC.

In the exam

For a trace table, take one instruction at a time and update ACC, IX and memory after each line. State the addressing mode precisely: LDM #n loads the value n; LDD address loads the contents of that address; LDI goes via an address; LDX adds IX to the operand. For the assembler, describe Pass 1 (remove comments, build the symbol table) then Pass 2 (generate machine code using the table). Group instructions correctly, e.g. CMP is a compare and JPE a conditional jump.

Worked example

Address 60 contains 12 and address 61 contains 5. What does address 62 contain after this program?
LDD 60
SUB 61
CMP #7
JPE SKIP
INC ACC
SKIP: STO 62

  1. LDD 60: ACC = 12 (the contents of address 60).
  2. SUB 61: ACC = 12 − 5 = 7.
  3. CMP #7: ACC equals 7, so the compare is True and JPE jumps to SKIP; INC ACC is not run.
  4. STO 62: the value 7 is copied to address 62.

Answer: Address 62 contains 7.

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← Central Processing Unit (CPU) architectureBit manipulation →Take a Computer Science AS test