AL

Assembly Language

Understanding low-level programming, machine code translation, and addressing modes

Learning Objectives

By the end of this lesson, you will be able to:

  • Show understanding of the relationship between assembly language and machine code
  • Describe the different stages of the assembly process for a two-pass assembler
  • Apply the two-pass assembler process to a given simple assembly language program
  • Trace a given simple assembly language program
  • Show understanding that a set of instructions are grouped into categories
  • Understand different addressing modes: Immediate, Direct, Indirect, Indexed, Relative
  • Explain how bitwise logic operations work in assembly language
  • Trace assembly language programs using trace tables

Key Terms

Machine Code

The only programming language that a CPU can execute directly, consisting of binary instructions

Assembly Language

A low-level language where opcodes are written as mnemonics and operands have character representation

Opcode

The part of an instruction that defines the action to be carried out by the CPU

Operand

The part of an instruction that defines any data needed by the instruction

Assembler

A language translator used to translate an assembly language program into machine code

Addressing Mode

Defines how a value should be found that has to be loaded into a register

ACC (Accumulator)

A special register used for arithmetic operations and data movement

IX (Index Register)

A register used in indexed addressing to form memory addresses

Direct Addressing

Contents of the memory location in the operand are used directly

Indirect Addressing

The operand contains an address that points to another address where the data is stored

Indexed Addressing

The address is calculated by adding the contents of the index register to the operand address

Immediate Addressing

The operand itself is the value to be used in the instruction

Machine Code and Assembly Language

At the lowest level, computers understand only machine code - binary instructions that tell the CPU exactly what to do. Assembly language provides a more human-readable way to write these low-level instructions.

Machine Code

  • The only programming language that a CPU can execute directly
  • Each different type of computer chip has its own set of machine code instructions
  • Each machine code instruction performs one simple task
  • Machine code is binary, but often displayed as hexadecimal for readability
  • An instruction contains an opcode and usually an operand
Real Example:

Think of machine code like giving your friend very specific, step-by-step instructions: "Take 3 steps forward, turn left 90 degrees, take 2 steps forward." The CPU needs this level of detail.

Assembly Language

  • A low-level language related to machine code
  • Opcodes are written as mnemonics (easy-to-remember abbreviations)
  • Operands have character representation
  • Each processor has its own assembly language
  • Must be translated to machine code using an assembler
Translation Example:
LDD Total → 0140 → 00000000110000000
Assembly → Hex → Binary

Machine Code Structure

Instruction Structure

Typical Machine Code Instruction
Opcode (4 bits) Address mode (2 bits) Register (2 bits)
| 0101 | 01 | 10 |
Operand (16 bits)
00000000110000000
Key Features
  • Machine code consists of a sequence of instructions
  • Each instruction contains an opcode
  • An instruction may have 0 to 3 operands
  • Different processors have different instruction sets
  • Comparable operations exist across processors but with different coding

Assembly Language Structure

Assembly vs Machine Code Comparison

Assembly Language Machine Code Description
LDD Total 0140 Load data from address labelled "Total"
ADD 20 0214 Add value at address 20 to accumulator
STO Total 0340 Store accumulator to address labelled "Total"

The assembler translates assembly language into machine code, checking syntax and ensuring only valid opcodes from the instruction set are used.

Activity 1: Assembly Language Translation

Convert the following assembly language instructions into the format shown in the table below:

  1. LDM #100 - Load the immediate value 100 into the accumulator
  2. ADD Total - Add the value at address "Total" to the accumulator
  3. STO Result - Store the accumulator at address "Result"
Assembly Machine Code (Hex) Machine Code (Binary)
LDD Total 0140 00000000110000000
Solution:
Assembly Machine Code (Hex) Machine Code (Binary) Explanation
LDM #100 01C8 0000000111001000 Load immediate value 100 (C8 in hex)
ADD Total 02[address] 00000010[address] ADD opcode (02) plus address of "Total"
STO Result 03[address] 00000011[address] STO opcode (03) plus address of "Result"

Note: The exact binary/hex values depend on the specific instruction set and memory addresses assigned to labels "Total" and "Result".

Check Your Understanding: Machine Code & Assembly

Answer
  • [1 mark] Assembly language is a low-level language that uses mnemonics to represent machine code instructions
  • [1 mark] Assembly language must be translated into machine code by an assembler before the CPU can execute it
  • [Additional] Each processor has its own assembly language that corresponds to its specific machine code instruction set
Answer
  • [1 mark] Opcode - defines the action to be carried out by the CPU
  • [1 mark] Operand - defines any data needed by the instruction
  • [Additional] Some instructions may not have an operand, while others may have up to three operands
Answer
  • [1 mark] Hexadecimal is more compact and easier for humans to read than binary
  • [1 mark] It reduces the chance of errors when programmers need to examine or modify machine code
  • [Additional] Each hexadecimal digit represents 4 binary bits, making conversion between the two straightforward
Answer
  • [1 mark] To translate assembly language programs into machine code
  • [1 mark] To check the syntax of assembly language programs and identify errors before execution
  • [Additional] Assemblers speed up development time by catching errors during translation rather than during program execution
Answer
  • [1 mark] Each processor has a different instruction set (different machine code)
  • [1 mark] Assembly language mnemonics directly correspond to specific machine code instructions for that processor
  • [Additional] While operations may be comparable across processors (e.g., ADD, SUB), the actual binary encoding differs between processor architectures

Assembly Language Instructions

Assembly language instructions are grouped into categories based on their function. Understanding these groups helps you organize and write assembly programs effectively.

Data Movement Instructions

These instructions allow data to be copied between memory locations and registers. The accumulator (ACC) is a special register used for most operations.

LDD <address>

Direct Addressing: Load content of <address> to ACC

Example: LDD 200
LDI <address>

Indirect Addressing: <address> holds the address to be used; load content of this second address to ACC

Example: LDI 200
LDX <address>

Indexed Addressing: Form address from <address> + content of IX; copy content of this calculated address to ACC

Example: LDX 200
LDR #n

Immediate Addressing: Load number n to IX

Example: LDR #10
LDR ACC

Load the number in accumulator into IX

Example: LDR ACC
LDM #n

Immediate Addressing: Load number n to ACC

Example: LDM #100
MOV <register>

Move the contents of the accumulator to the register (IX)

Example: MOV IX
STO <address>

Store contents of ACC into specified address (direct addressing)

Example: STO Total

Input and Output Instructions

IN

Key in a character and store its ASCII value in ACC

Real Example:

Like typing a letter on your keyboard - the computer needs to read what you typed and store it somewhere to use it.

OUT

Output to the screen the character whose ASCII value is stored in ACC

Real Example:

Like displaying a character on your screen - the computer needs to send the character data from memory to the display.

Arithmetic Operation Instructions

These instructions perform calculations on data stored in the accumulator. The answer is always stored in the accumulator, overwriting the original data.

ADD <address>

Add the contents of the specified address to the ACC

Example: ADD Total
ADD #n

Add the denary number n to the ACC

Example: ADD #5
SUB <address>

Subtract the contents of the specified address from the ACC

Example: SUB Value
SUB #n

Subtract the number n from the ACC

Example: SUB #3
INC <register>

Add 1 to the contents of the register (ACC or IX)

Example: INC ACC
DEC <register>

Subtract 1 from the contents of the register (ACC or IX)

Example: DEC IX

Control Flow Instructions

These instructions change the order of execution. Jump means change the Program Counter (PC) to the address specified, so the next instruction executed is at that address.

Unconditional & Conditional Jumps

  • JMP <address> - Unconditionally jump to the address specified
  • JPN <address> - Jump to address if the previous compare was False
  • JPE <address> - Jump to address if the previous compare was True

Compare Instructions

  • CMP <address> - Compare contents of ACC with contents of <address>
  • CMP #n - Compare contents of ACC with the number n
  • CMI <address> - Indirect compare: address to be used is the contents of the specified address
  • END - Returns control to the operating system

Real-Life Example: Simple Calculator

Think of assembly instructions like giving someone a recipe:

Recipe Instructions
  • Take 2 eggs from the fridge (LDD Eggs)
  • Add 100g of flour (ADD #100)
  • Mix them together (process happens in ACC)
  • Pour into bowl (STO Mixture)
  • If mixture looks good, bake it (CMP #good, JPE Bake)
Assembly Equivalent
LDD Eggs
ADD #100
STO Mixture
CMP #good
JPE Bake

Activity 2: Instruction Classification

Classify the following assembly language instructions into their correct categories:

Instructions:
  1. LDM #50
  2. ADD Total
  3. IN
  4. JMP Loop
  5. CMP #0
  6. STO Result
  7. OUT
  8. SUB #10
Categories:
  • Data Movement
  • Input/Output
  • Arithmetic Operations
  • Control Flow/Compare
Solution:
Data Movement:
  • LDM #50 - Load immediate value to ACC
  • STO Result - Store ACC to memory
Input/Output:
  • IN - Input character to ACC
  • OUT - Output character from ACC
Arithmetic Operations:
  • ADD Total - Add memory value to ACC
  • SUB #10 - Subtract immediate value from ACC
Control Flow/Compare:
  • JMP Loop - Unconditional jump
  • CMP #0 - Compare ACC with zero

Check Your Understanding: Assembly Instructions

Answer
  • [1 mark] Allow data stored at one location to be copied into the accumulator
  • [1 mark] Enable data to be moved between memory locations and registers for processing
  • [Additional] Data can then be stored at another location, used in calculations, used for comparisons, or output
Answer
  • [1 mark] Answers to calculations are always stored in the accumulator
  • [1 mark] The result overwrites the original data that was in the accumulator
  • [Additional] This means you need to store important values elsewhere before performing operations that will overwrite them
Answer
  • [1 mark] Keys in a character from the keyboard
  • [1 mark] Stores the ASCII value of that character in the accumulator
  • [Additional] No operand is required as input always goes to the accumulator
Answer
  • [1 mark] Both follow a compare instruction (CMP)
  • [1 mark] JPE jumps to the address if the compare was True
  • [1 mark] JPN jumps to the address if the compare was False
  • [Additional] These enable conditional branching in programs, similar to IF-THEN-ELSE in high-level languages
Answer
  • [1 mark] Compares the contents of the accumulator with another value
  • [1 mark] Sets internal flags that can be tested by conditional jump instructions (JPE/JPN)
  • [Additional] The compare doesn't change any register values, it only sets status flags

Addressing Modes

An addressing mode defines how a value should be found that has to be loaded into a register. Different addressing modes are used depending on the requirements of the program.

Direct Addressing

How it Works

Contents of the memory location specified in the operand are used directly. Also known as absolute addressing.

Example:

If memory location at address 200 contains value 78, then LDD 200 would store 78 in the accumulator.

Real-Life Analogy

Like going directly to a specific house address to pick up a package. You know exactly where to go.

Memory Visualization
Address 200 78
Address 201 42
Address 202 15
LDD 200 → Goes directly to address 200 → Loads value 78

Indirect Addressing

How it Works

The operand contains an address that points to another address where the actual data is stored.

Example:

If address 200 contains value 20, and address 20 contains value 5, then LDI 200 would store 5 in the accumulator.

Real-Life Analogy

Like going to a post office box: The box number (first address) contains a key to another box (second address) where your package is.

Memory Visualization
Address 200 20
Address 20 5
LDI 200 → Goes to address 200 (finds 20) → Goes to address 20 → Loads value 5

Indexed Addressing

How it Works

The address is calculated by adding the contents of the index register (IX) to the address in the operand.

Example:

If IX contains value 4 and address 204 contains value 17, then LDX 200 would store 17 in the accumulator (200 + 4 = 204).

Real-Life Analogy

Like using a base address plus an offset: "Start at house number 200, then go 4 houses down."

Memory Visualization
IX Register 4
Address 204 17
LDX 200 → 200 + IX(4) = 204 → Goes to address 204 → Loads value 17

Immediate Addressing

How it Works

The operand itself is the value to be used in the instruction, not an address.

Example:

LDM #200 would store 200 directly in the accumulator.

Number formats:

  • #48 - Denary value 48
  • #B00110000 - Binary equivalent
  • #&30 - Hexadecimal equivalent

Real-Life Analogy

Like being given the actual item instead of directions to find it: "Here's £20" instead of "Go to this address to collect £20".

Instruction Visualization
LDM #200
The value 200 is part of the instruction itself
ACC ← 200

Relative Addressing

How it Works

The memory address used is the current memory address added to the operand.

Example:

JMR #5 would transfer control to the instruction 5 locations after the current instruction.

Real-Life Analogy

Like giving directions relative to your current position: "From where you are now, go forward 5 steps."

Symbolic Addressing

How it Works

A label is used instead of a numerical address. This makes programs easier to read and modify.

Example:

If memory location with address labelled MyStore contains value 20, then LDD MyStore would store 20 in the accumulator.

Real-Life Analogy

Like using a person's name instead of their house address: "Go to Sarah's house" instead of "Go to 123 Main Street".

Benefit: If Sarah moves, you still say "Go to Sarah's house" - the assembler updates the actual address automatically.

Addressing Mode Summary

Addressing Mode Assembly Example What Happens Real-Life Analogy
Direct LDD 200 Loads value from address 200 Go directly to house number 200
Indirect LDI 200 200 contains address 20, loads value from address 20 Box 200 contains key to box 20
Indexed LDX 200 Loads value from address (200 + IX) Start at house 200, go IX houses forward
Immediate LDM #200 Loads the value 200 directly Here's £200 (the money itself)
Relative JMR #5 Jump to current address + 5 From here, go 5 steps forward
Symbolic LDD Total Loads value from address labelled "Total" Go to Sarah's house (not 123 Main St)

Activity 3: Addressing Mode Identification

Identify the addressing mode used in each of the following assembly language instructions:

  1. LDM #48 - Load the value 48 into the accumulator
  2. LDD Result - Load the value at memory location labelled "Result"
  3. LDI Pointer - "Pointer" contains an address; load value from that address
  4. LDX Base - Load value from address calculated as Base + IX
  5. JMR #-3 - Jump to instruction 3 locations before current one
  6. ADD #10 - Add the value 10 to the accumulator
Solution:
  1. Immediate Addressing - The operand (#48) is the actual value to be loaded
  2. Symbolic Addressing (which uses Direct Addressing) - "Result" is a label for a memory address
  3. Indirect Addressing - "Pointer" contains an address that points to the actual data
  4. Indexed Addressing - Address is calculated as Base address + contents of IX
  5. Relative Addressing - Jump relative to current position (-3 locations)
  6. Immediate Addressing - The operand (#10) is the actual value to be added

Check Your Understanding: Addressing Modes

Answer
  • [1 mark] Direct addressing uses the operand as the actual memory address containing the data
  • [1 mark] Indirect addressing uses the operand as an address that contains another address where the data is stored
  • [1 mark] Direct: LDD 200 loads from address 200; Indirect: LDI 200 uses value at 200 as address to load from
Answer
  • [1 mark] The address is calculated by adding the contents of the index register (IX) to the address in the operand
  • [1 mark] LDX 200 with IX=4 would load from address 204 (200 + 4)
  • [1 mark] Useful for accessing arrays or data structures where you want to access elements at an offset from a base address
Answer
  • [1 mark] Denary: #48 specifies the denary value 48
  • [1 mark] Binary: #B00110000 specifies the binary equivalent
  • [1 mark] Hexadecimal: #&30 specifies the hexadecimal equivalent
  • [Additional] All three represent the same value (48 in denary)
Answer
  • [1 mark] Makes programs easier to read and understand (meaningful names instead of numbers)
  • [1 mark] Makes programs easier to modify - if data moves to a different address, only the label definition needs updating
  • [Additional] The assembler converts labels to actual addresses during assembly
Answer
  • [1 mark] When jumping forward or backward a fixed number of instructions from the current position
  • [1 mark] Example: JMR #5 jumps to instruction 5 locations after current one; JMR #-3 jumps 3 locations back
  • [Additional] Useful for loops or conditional skipping of instructions

Bitwise Logic and Program Tracing

Bitwise Logic Operations

Bitwise logic operations work on individual bits of data. The operand for a bitwise logic operation is called a mask because it can effectively cover some bits and only affect specific bits.

AND #Bn

Bitwise AND operation of the contents of ACC with binary number n

Example: AND #B00001111
AND <address>

Bitwise AND operation of ACC with contents of <address>

Example: AND Mask
XOR #Bn

Bitwise XOR operation of ACC with binary number n

Example: XOR #B11110000
XOR <address>

Bitwise XOR operation of ACC with contents of <address>

Example: XOR Value
OR #Bn

Bitwise OR operation of ACC with binary number n

Example: OR #B00110011
OR <address>

Bitwise OR operation of ACC with contents of <address>

Example: OR Pattern

Real-Life Example: Using Masks

Think of a mask like a stencil for spray painting: only the holes in the stencil allow paint through to affect the surface.

AND Mask Example

To extract only the lower 4 bits of a byte (clear upper 4 bits):

ACC = B11010110 (214 decimal)
AND #B00001111 (mask)
Result: B00000110 (6 decimal)
OR Mask Example

To set specific bits to 1 (turn on flags):

ACC = B00001000 (8 decimal)
OR #B10000001 (mask)
Result: B10001001 (137 decimal)

Computer Arithmetic Flags

Status Register Flags

Arithmetic operations can lead to incorrect answers if overflow occurs. The status register contains flags that identify specific conditions:

C
Carry Flag

Set to 1 if there is a carry from the most significant bit

N
Negative Flag

Set to 1 if a result is negative (most significant bit = 1)

V
Overflow Flag

Set to 1 if overflow is detected in signed arithmetic

Tracing Assembly Language Programs

Tracing involves executing a program step-by-step and recording the values in registers and memory locations. This helps understand how the program works and debug errors.

Tracing Example from PDF

Assembly Program
100 IN
101 STO 200
102 IN
103 STO 201
104 IN
105 ADD 200
106 STO 200
107 ADD 201
108 INC ACC
109 OUT
110 END

Initial inputs: 15, 27, 31

Trace Table
Instruction ACC Mem 200 Mem 201 Output
100 IN 15
101 STO 200 15 15
102 IN 27 15
103 STO 201 27 15 27
104 IN 31 15 27
105 ADD 200 46 15 27
106 STO 200 46 46 27
107 ADD 201 73 46 27
108 INC ACC 74 46 27
109 OUT 74 46 27 74

What the program does: Reads three numbers, adds the first and third, stores result, adds the second, increments by 1, outputs final result.

Interactive Program Tracing

Trace this simple assembly program step by step. The program reads two numbers and outputs their sum:

1. IN
2. STO 100
3. IN
4. ADD 100
5. OUT
6. END
Input Values
Trace Step-by-Step
Current State

Click "Execute Next Instruction" to begin tracing...

Activity 4: Program Tracing

Trace the following assembly language program. Complete the trace table with the values after each instruction is executed.

Program
LDM #10
STO 200
LDM #5
ADD 200
INC ACC
STO 201
LDM #3
SUB 201
OUT
END
Trace Table (Complete)
Instruction ACC Mem 200 Mem 201 Output
LDM #10 ? ? ? ?
STO 200 ? ? ? ?
LDM #5 ? ? ? ?
ADD 200 ? ? ? ?
INC ACC ? ? ? ?
STO 201 ? ? ? ?
LDM #3 ? ? ? ?
SUB 201 ? ? ? ?
OUT ? ? ? ?
Solution:
Instruction ACC Mem 200 Mem 201 Output
LDM #10 10
STO 200 10 10
LDM #5 5 10
ADD 200 15 10
INC ACC 16 10
STO 201 16 10 16
LDM #3 3 10 16
SUB 201 -13 10 16
OUT -13 10 16 -13

Program Summary: The program calculates (5 + 10 + 1) = 16, stores it, then calculates 3 - 16 = -13 and outputs -13.

Check Your Understanding: Bitwise Logic & Tracing

Answer
  • [1 mark] A mask is an operand used in bitwise logic operations
  • [1 mark] It "covers" some bits so that only specific bits are affected by the operation
  • [Additional] Example: AND #B00001111 clears the upper 4 bits and preserves the lower 4 bits
Answer
  • [1 mark] C (Carry flag): Set to 1 if there is a carry from the most significant bit
  • [1 mark] N (Negative flag): Set to 1 if a result is negative (MSB = 1)
  • [1 mark] V (Overflow flag): Set to 1 if overflow is detected in signed arithmetic
  • [Additional] These flags help detect and handle arithmetic errors like overflow
Answer
  • [1 mark] Tracing involves executing a program step-by-step and recording register/memory values
  • [1 mark] It helps understand how a program works and identify logic errors
  • [1 mark] Useful for debugging and verifying program correctness
  • [Additional] Trace tables provide a systematic way to document program execution
Answer
  • [1 mark] To extract specific bits from a byte (e.g., get only the lower 4 bits)
  • [1 mark] Example: AND #B00001111 clears the upper 4 bits, keeping only lower 4 bits
  • [Additional] Useful for processing packed data or checking status bits
Answer
  • [1 mark] The final output was 74
  • [1 mark] Calculation: First input (15) + Third input (31) = 46, stored at address 200
  • [1 mark] Then: 46 + Second input (27) = 73, then INC ACC makes it 74, which is output
  • [Additional] The program reads three numbers and outputs (first + third + second + 1)

Key Takeaways

  • Machine code is the only language CPUs understand directly - it's binary instructions specific to each processor type
  • Assembly language uses mnemonics to represent machine code instructions, making low-level programming more human-readable
  • Assemblers translate assembly language into machine code, checking syntax and identifying errors
  • Assembly instructions are grouped into categories: Data Movement, Input/Output, Arithmetic Operations, and Control Flow
  • The accumulator (ACC) is a special register used for most operations - results are stored here
  • Addressing modes define how to find data: Direct, Indirect, Indexed, Immediate, Relative, and Symbolic
  • Direct addressing uses the operand as the actual memory address
  • Indirect addressing uses the operand as an address that contains another address
  • Indexed addressing calculates addresses by adding the index register (IX) to a base address
  • Immediate addressing uses the operand itself as the value (not an address)
  • Bitwise operations (AND, OR, XOR) work on individual bits using masks to affect specific bits
  • Status flags (C, N, V) indicate arithmetic conditions like carry, negative results, and overflow
  • Program tracing involves step-by-step execution to understand program behavior and debug errors
  • Assembly programs require more instructions than high-level languages to perform the same tasks

Question Bank

Marking Scheme & Answer
  • [1 mark] Machine code is the binary language that CPUs execute directly
  • [1 mark] Assembly language uses mnemonics (abbreviations) to represent machine code instructions
  • [1 mark] Each processor has its own assembly language that corresponds to its machine code instruction set
  • [1 mark] An assembler translates assembly language into machine code before execution
  • [Additional] Assembly language makes low-level programming more readable and less error-prone than writing machine code directly
Marking Scheme & Answer
  • [1 mark] A machine code instruction consists of binary code with a defined number of bits
  • [1 mark] It contains an opcode that defines the action to be performed
  • [1 mark] Most instructions also contain one or more operands that define data needed by the instruction
  • [1 mark] Instructions may have 0 to 3 operands depending on the operation
  • [Additional] Different processors have different instruction formats and bit allocations for opcodes and operands
Marking Scheme & Answer
Direct Addressing:
  • Operand is the actual memory address
  • Example: LDD 200 loads from address 200
  • Also called absolute addressing
Indirect Addressing:
  • Operand contains an address that points to another address
  • Example: LDI 200 uses value at 200 as address to load from
  • Two memory accesses required
Indexed Addressing:
  • Address calculated as operand + contents of IX
  • Example: LDX 200 with IX=4 loads from address 204
  • Useful for array access
Key Difference: Direct uses the operand directly as address; indirect uses operand as pointer to address; indexed calculates address using operand + IX.
Marking Scheme & Answer
  • [1 mark] LDM #n - Load immediate: loads the value n directly into the accumulator
  • [1 mark] STO <address> - Store: stores the contents of the accumulator at the specified memory address
  • [1 mark] ADD <address> - Add: adds the value at the specified address to the accumulator
  • [1 mark] CMP <address> - Compare: compares the accumulator with the value at the specified address
  • [1 mark] JPE <address> - Jump if equal: jumps to the specified address if the previous compare was true
Marking Scheme & Answer
  • [1 mark] Bitwise operations (AND, OR, XOR) work on individual bits of data
  • [1 mark] A mask is an operand that "covers" specific bits during the operation
  • [1 mark] AND with mask: clears bits where mask has 0, preserves bits where mask has 1
  • [1 mark] OR with mask: sets bits to 1 where mask has 1, preserves bits where mask has 0
  • [Additional] Example: AND #B00001111 clears upper 4 bits, keeps lower 4 bits
Marking Scheme & Answer
Program:
LDM #8
STO 100
LDM #3
SUB 100
STO 101
LDM #10
ADD 101
OUT
END
Trace Table Solution:
Instruction ACC Mem 100 Mem 101 Output
LDM #8 8
STO 100 8 8
LDM #3 3 8
SUB 100 -5 8
STO 101 -5 8 -5
LDM #10 10 8 -5
ADD 101 5 8 -5
OUT 5 8 -5 5
Program Summary: Calculates 3 - 8 = -5, stores it, then calculates 10 + (-5) = 5 and outputs 5.
Marking Scheme & Answer
  • [1 mark] Symbolic addressing uses labels instead of numerical addresses in assembly language
  • [1 mark] Advantage: Makes programs easier to read and understand (meaningful names)
  • [1 mark] Advantage: Makes programs easier to modify - if data moves, only label definition needs updating
  • [Additional] The assembler converts labels to actual addresses during the assembly process
Marking Scheme & Answer
  • [1 mark] Indexed addressing calculates the effective address by adding the contents of the index register (IX) to the address in the operand
  • [1 mark] The instruction LDX <address> loads from address calculated as <address> + contents of IX
  • [1 mark] Example: If IX contains 4 and LDX 200 is executed, it loads from address 204 (200 + 4)
  • [1 mark] Useful for accessing arrays: base address in operand, index in IX gives array element address
  • [Additional] By changing IX, you can access different elements of the same array without changing the instruction
Marking Scheme & Answer
  • [1 mark] IN reads a character from the keyboard and stores its ASCII value in the accumulator
  • [1 mark] OUT outputs to the screen the character whose ASCII value is stored in the accumulator
  • [Additional] No operand is needed for either instruction since input/output always involves the accumulator
Marking Scheme & Answer
  • [1 mark] Translates assembly language programs into machine code that the CPU can execute
  • [1 mark] Checks the syntax of assembly language programs for errors
  • [1 mark] Ensures only valid opcodes from the processor's instruction set are used
  • [1 mark] Converts symbolic addresses (labels) into actual memory addresses
  • [Additional] Speeds up development by identifying errors during translation rather than during program execution