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
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
Machine Code Structure
Instruction Structure
Typical Machine Code Instruction
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:
- LDM #100 - Load the immediate value 100 into the accumulator
- ADD Total - Add the value at address "Total" to the accumulator
- 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
1. What is the relationship between assembly language and machine code? [2 marks]
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
2. What are the two main components of a machine code instruction? [2 marks]
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
3. Why is machine code displayed in hexadecimal rather than binary? [2 marks]
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
4. What is the purpose of an assembler? [2 marks]
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
5. Why does each processor type have its own assembly language? [2 marks]
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.
Direct Addressing: Load content of <address> to ACC
Indirect Addressing: <address> holds the address to be used; load content of this second address to ACC
Indexed Addressing: Form address from <address> + content of IX; copy content of this calculated address to ACC
Immediate Addressing: Load number n to IX
Load the number in accumulator into IX
Immediate Addressing: Load number n to ACC
Move the contents of the accumulator to the register (IX)
Store contents of ACC into specified address (direct addressing)
Input and Output Instructions
IN
Key in a character and store its ASCII value in ACC
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
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 the contents of the specified address to the ACC
Add the denary number n to the ACC
Subtract the contents of the specified address from the ACC
Subtract the number n from the ACC
Add 1 to the contents of the register (ACC or IX)
Subtract 1 from the contents of the register (ACC or 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
Activity 2: Instruction Classification
Classify the following assembly language instructions into their correct categories:
Instructions:
- LDM #50
- ADD Total
- IN
- JMP Loop
- CMP #0
- STO Result
- OUT
- 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
1. What is the purpose of data movement instructions? [2 marks]
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
2. How do arithmetic operation instructions handle their results? [2 marks]
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
3. What does the IN instruction do? [2 marks]
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
4. What is the difference between JPE and JPN instructions? [3 marks]
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
5. What happens when a CMP instruction is executed? [2 marks]
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.
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.
Indirect Addressing
How it Works
The operand contains an address that points to another address where the actual data is stored.
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.
Indexed Addressing
How it Works
The address is calculated by adding the contents of the index register (IX) to the address in the operand.
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."
Immediate Addressing
How it Works
The operand itself is the value to be used in the instruction, not an address.
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".
Relative Addressing
How it Works
The memory address used is the current memory address added to the operand.
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.
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".
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:
- LDM #48 - Load the value 48 into the accumulator
- LDD Result - Load the value at memory location labelled "Result"
- LDI Pointer - "Pointer" contains an address; load value from that address
- LDX Base - Load value from address calculated as Base + IX
- JMR #-3 - Jump to instruction 3 locations before current one
- ADD #10 - Add the value 10 to the accumulator
Solution:
- Immediate Addressing - The operand (#48) is the actual value to be loaded
- Symbolic Addressing (which uses Direct Addressing) - "Result" is a label for a memory address
- Indirect Addressing - "Pointer" contains an address that points to the actual data
- Indexed Addressing - Address is calculated as Base address + contents of IX
- Relative Addressing - Jump relative to current position (-3 locations)
- Immediate Addressing - The operand (#10) is the actual value to be added
Check Your Understanding: Addressing Modes
1. What is the difference between direct and indirect addressing? [3 marks]
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
2. How does indexed addressing work? [3 marks]
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
3. What are the three ways to specify a value in immediate addressing? [3 marks]
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)
4. What is the advantage of using symbolic addressing? [2 marks]
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
5. Give an example of when you would use relative addressing. [2 marks]
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.
Bitwise AND operation of the contents of ACC with binary number n
Bitwise AND operation of ACC with contents of <address>
Bitwise XOR operation of ACC with binary number n
Bitwise XOR operation of ACC with contents of <address>
Bitwise OR operation of ACC with binary number n
Bitwise OR operation of ACC with contents of <address>
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):
OR Mask Example
To set specific bits to 1 (turn on flags):
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:
Set to 1 if there is a carry from the most significant bit
Set to 1 if a result is negative (most significant bit = 1)
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
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:
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
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
1. What is a mask in the context of bitwise operations? [2 marks]
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
2. What is the purpose of the three arithmetic flags (C, N, V)? [3 marks]
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
3. What is program tracing and why is it useful? [3 marks]
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
4. Give an example of when you would use the AND operation with a mask. [2 marks]
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
5. In the tracing example from the PDF, what was the final output and why? [3 marks]
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
1. Explain the relationship between machine code and assembly language. [4 marks]
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
2. Describe the structure of a typical machine code instruction. [4 marks]
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
3. Compare and contrast direct, indirect, and indexed addressing modes. [6 marks]
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
4. Explain the purpose of the following assembly language instructions: LDM, STO, ADD, CMP, JPE. [5 marks]
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
5. What are bitwise logic operations and how are masks used with them? [4 marks]
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
6. Trace the following assembly program and complete the trace table. [6 marks]
Marking Scheme & Answer
Program:
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 |
7. What is the purpose of symbolic addressing and what are its advantages? [3 marks]
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
8. Describe how indexed addressing works with an example. [4 marks]
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
9. Explain the difference between the IN and OUT instructions. [2 marks]
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
10. What is the role of an assembler in the development of assembly language programs? [4 marks]
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