4.2 Assembly Language Student
4.2 Assembly Language Student
Communication with a
Computer
High level languages – closer to
C, how humans understand
Pascal, communication
Java, VB
Assembly
language Low level languages –
closer to how computers
understand communication
Machine code
Hardware
Assembly Language and
Machine Code
Machine code – the
binary programming
language that the
CPU understands
Assembly language –
a low level processor
chip specific
programming
language that uses
mnemonics.
Assembly Language Instruction
Set
You will need to familiarise with an assembly language
instruction set (the set on the right can be viewed in
OneNote).
An assembler is used to translate assembly language into machine code and also checks
the syntax is correct. Checking the syntax is important to ensure the opcodes match the
instruction set being used by the processor.
There are two types of assembler – single pass and two pass. You need to know about two
pass assemblers.
A two pass assembler produces an object program that can be stored, loaded and then
executed at a later stage. This requires the use of a loader.
Two pass assemblers need to scan the source program twice, so they can replace the
labels in the assembly program with memory addresses in the machine code program
Stages of Assembly Process Pass 1 is like filtering the
executable components and
Pass 1 sorting the program into memory
• Read the assembly language program one line at a time. locations line by line.
• Ignore anything not required, such as comments.
• Allocate a memory address for the line of code. Pass 2 converts assembly code into
• Check the opcode is in the instruction set. object code before storing or
• Add any new labels to the symbol table with the address, if known. running.
• Place address of labelled instruction in the symbol table.
Pass 2
• Read the assembly language program one line at a time.
• Generate object code, including opcode and operand, from the symbol table generated in Pass 1.
• Save or execute the program.
Label Memory address
Absolute/Direct addressing – contents of memory location in operand are used. E.g. if address location 200
contained 20, instruction LDD 200 would store 20 in ACC.
Indirect addressing – the contents of the contents of the memory location is used. E.g. if address 200
contained the value 20 and address 20 contains the value 5, LDI 200 would load 5 into the ACC.
Indexed addressing – contents of memory location found by adding the IR value to the address memory
location. E.g. if IR value was 4 and memory location 204 contained 17, LDX 200 would load 17 into ACC.
Relative addressing – the memory address used is the current memory address added to the operand. E.g.
JMR #5 would transfer control to the instruction 5 locations after the current instruction.
Symbolic addressing – only used in assembly language programming. Uses a label for a memory location
instead of a value. Similar to how a variable is used in HLL.
Assembly Language Examples
Consider this HLL instruction:
total = first + second + third
first: #20
second: #30
third: #40
total: #0
The program will be loaded into memory address 100. We will produce a symbol table and trace table from
this.
Label Opcode
CIR Opcode Operand ACC first 106 second 107 third 108 total 109
CIR Opcode Operand ACC first 106 second 107 third 108 total 109
CIR Opcode Operand ACC first 106 second 107 third 108 total 109
CIR Opcode Operand ACC first 106 second 107 third 108 total 109
CIR Opcode Operand ACC first 106 second 107 third 108 total 109