Show understanding of the need for assembler software for translation of assembly language programs
Show understanding of the need for a compiler for translation of high-level language programs
Show understanding of the need for an interpreter for translation and execution of high-level language programs
Explain benefits and drawbacks of using either a compiler or interpreter and justify the use of each
Show awareness that high-level language programs may be partially compiled and partially interpreted (e.g., Java)
Describe features found in a typical Integrated Development Environment (IDE)
🌟 Did You Know?
Language Translators are programs that translate source code written in Assembly Language or High-Level Language into object code (machine language). Without translators, programmers would have to write programs directly in binary (0s and 1s), which would be extremely time-consuming and error-prone!
1. What is a Language Translator?
📖 Definition
A language translator is a program that translates program source code into machine code so that it can be executed directly by a processor.
There are three main types of language translators:
Translator Type
Source Language
Purpose
Assembler
Assembly Language (Low-level)
Translates mnemonics into machine code
Compiler
High-Level Language
Translates entire program before execution
Interpreter
High-Level Language
Translates and executes line by line
1.1 Why Do We Need Translators?
Writing a program directly in machine code (binary) would:
Take a very long time to write
Undoubtedly lead to a multitude of errors
Be extremely difficult to debug and maintain
Require programmers to memorize binary instruction codes
💡 Exam Tip
Remember: Low-level languages (like assembly) are translated by assemblers, while high-level languages (like Python, Java) are translated by compilers or interpreters.
2. Assembler Software
📖 What is an Assembler?
An assembler is a software that converts assembly language code into machine code. It translates mnemonics (symbolic representations) into binary instructions that the processor can execute.
2.1 What is Assembly Language?
Assembly language is a low-level language that gives instructions to processors for different tasks. It is specific to any processor and uses:
Mnemonics: Symbolic representation of machine-level instructions (opcode)
Operands: The data or addresses the instruction operates on
Labels: Symbolic names for memory addresses
Example: ADD A, B
Here, ADD is the mnemonic (tells processor to add), A and B are the operands. Other mnemonics include SUB, MUL, DIV, MOV, etc.
⚠️ Important
Assembly language programs are machine dependent - they are not portable from one type of computer/processor to another. Each processor architecture has its own assembly language.
2.2 Types of Assemblers
📝 One-Pass (Single-Pass) Assembler
Performs the whole conversion in one go
Puts machine code instructions straight into computer memory
Cannot handle forward references easily
Faster but less flexible
📝 Two-Pass (Multi-Pass) Assembler
Pass 1:
Reads assembly language program line by line
Creates Symbol Table with binary codes for symbolic names and labels
Creates Literal Table for constants used
Removal of comments and whitespace
Expansion of macros
Pass 2:
Replaces symbolic addresses with absolute addresses
Resolves forward references
Replaces symbolic opcodes with binary opcodes using opcode table
Generates final object code
2. Assembler (Continued)
2.3 Important Tables in Assembly
📖 Opcode Table
Stores the value of mnemonics and their corresponding numeric values. Example:
Mnemonic
Binary Opcode
ADD
00000001
SUB
00000010
MOV
00000011
📖 Symbol Table
Stores symbolic names (labels) used by the programmer and their corresponding memory addresses. Example:
Symbol
Address
START
1000
LOOP
1015
END
1050
📖 Location Counter
Stores the address of the location where the current instruction will be stored. It increments as the assembler processes each instruction.
2.4 Forward Reference Problem
⚠️ Forward Reference Problem
Rules for assembly programs state that a symbol should be defined somewhere in the program. However, in some cases a symbol may be used prior to its definition. Such a reference is called a forward reference.
Due to this, the assembler cannot translate instructions immediately, creating the forward reference problem. This is why two-pass assemblers are needed - the first pass builds the symbol table, and the second pass resolves all references.
3. Compiler
📖 What is a Compiler?
A compiler is a language translator that translates the entire source program written in a high-level language into object code in machine language before execution. The object code is saved as an executable file.
3.1 How a Compiler Works
📝 Steps in Compilation
Compiler program and source code file are made available (no data needed yet)
Compiler begins execution and reads the first line of source code
Line is analyzed. If an error is found, it is recorded
If no error is found, the line is converted to intermediate code
Next line of source code is read
When the whole source code has been processed:
If no errors: complete intermediate code is converted into object code
If errors found: list of errors is output, no object code produced
Object code is stored and can be executed later without the compiler
3.2 Advantages of Compilers
Advantage
Explanation
Speed of execution
Compiled programs run faster as translation is done in advance
Code optimization
Compiler can optimize the code for better performance
Source code protection
Users do not receive the source code, only executable
Distribution
Executable file can be distributed without compiler
No runtime translation
Compiler not needed at runtime
3.3 Disadvantages of Compilers
Disadvantage
Explanation
Memory intensive
Can require significant memory during compilation
Difficult debugging
Harder to test sections; errors shown after full compilation
Recompilation required
Any changes mean the program must be recompiled
Platform specific
Compiled code is designed for one specific processor
4. Interpreter
📖 What is an Interpreter?
An interpreter is a language translator that translates source code written in high-level language into object code during step-by-step execution of the program. No executable file of machine code is produced.
4.1 How an Interpreter Works
📝 Steps in Interpretation
Interpreter program, source code file, and data are all made available
Interpreter starts execution and reads the first line of source code
Line is analyzed for syntax errors
If an error is found, it is reported and interpreter halts
If no error, line is converted to intermediate code
Interpreter uses this intermediate code to execute the required action
Next line of source code is read and the process repeats
⚠️ Key Difference
Interpreters do NOT generate machine code directly. Instead, they call appropriate machine code subroutines to execute each statement.
4.2 Advantages of Interpreters
Advantage
Explanation
Easier debugging
Stops when it finds a specific syntax error, showing exact location
Immediate feedback
Errors can be corrected and processing continue from where it stopped
Less memory
Requires less RAM to process the code
Development friendly
Ideal for program development stage
Platform independent
Same source code can run on any machine with interpreter
4.3 Disadvantages of Interpreters
Disadvantage
Explanation
Slower execution
Each line is translated every time the program runs
Source code required
Source code must be distributed to users
No optimization
Code is executed as-is, no optimization performed
Interpreter needed
Interpreter must be available each time program runs
5. Compiler vs Interpreter Comparison
Aspect
Compiler
Interpreter
Translation
Entire program at once
One line at a time
Speed of execution
Fast (pre-translated)
Slow (translate each run)
Error detection
After full compilation
One at a time, immediate
Source code
Not distributed to users
Must be distributed
Executable file
Yes, created
No executable produced
Debugging
More difficult
Easier, immediate feedback
Memory needed
More memory intensive
Less memory required
Distribution
Only executable needed
Interpreter + source needed
Optimization
Code can be optimized
No optimization
Best use
Finished, distributed programs
Program development stage
🧠 Memory Trick
Compiler = Complete (translates entire program at once, Creates executable)
Interpreter = Immediate (translates line by line, shows errors Immediately)
6. Mixed Mode Translation
📖 What is Mixed Mode Translation?
Mixed mode translation combines features of both a compiler and an interpreter. The program is partially compiled into an intermediate form (bytecode), which is then interpreted at runtime.
6.1 How Mixed Mode Translation Works
📝 Steps in Mixed Mode Translation
Source code is compiled into intermediate code (not full machine code)
This intermediate code (e.g., bytecode) is interpreted by a virtual machine
Optionally, some parts may later be Just-In-Time (JIT) compiled for better performance
6.2 Java Example
Java uses mixed mode translation:
Java source code (.java) is compiled to bytecode (.class file)
Bytecode is platform-independent
Java Virtual Machine (JVM) interprets the bytecode
JVM can be installed on any platform (Windows, Mac, Linux)
Same bytecode runs on any machine with JVM
6.3 Comparison Table
Feature
Compiler
Interpreter
Mixed Mode
Translation
Entire program
Line at a time
To intermediate code
Speed
Fastest
Slowest
Medium (JIT helps)
Portability
Not portable
Not portable
Highly portable
Examples
C, C++
Python, JavaScript
Java, C#
💡 Exam Tip
When asked about Java's portability, mention: Java source code is compiled to bytecode, which is platform-independent. Any machine with a JVM can run the same bytecode file - this is "Write Once, Run Anywhere".
7. Integrated Development Environment (IDE)
📖 What is an IDE?
An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities to programmers for software development. It normally consists of at least a source code editor, build automation tools, and a debugger.
7.1 Features for Coding
📝 Context-Sensitive Prompts
Displays hints and choice of keywords appropriate at current insertion point
Shows available identifiers that might be appropriate
Predicts code being entered (autocomplete)
Speeds up coding by reducing typing effort
📝 Prettyprinting (Syntax Highlighting)
Automatically colour-codes different elements of code
Keywords, function calls, comments, strings shown in different colours
Example of Syntax Highlighting: defcalculate_sum(a, b): # This is a comment return a + b
7.2 Features for Error Detection
📝 Dynamic Syntax Checks
Performs syntax checks as code is being typed
Alerts programmer to errors immediately
Underlines or highlights statements with errors
Displays explanations when mouse hovers over error
Many errors can be found and corrected during writing
7. IDE Features (Continued)
7.3 Features for Presentation
📝 Expanding and Collapsing Code Blocks
Allows programmer to collapse blocks of statements into single line
Helps manage large programs with many lines
Reduces excessive scrolling
Procedure headings remain visible for reference
Programmer can focus on currently developed sections
7.4 Features for Debugging
📖 What is Debugging?
Debugging is the process of finding and correcting errors (bugs) in a program. A debugger is a program that runs the program under development and aids the debugging process.
📝 Single Stepping
Execute the program one line at a time
Allows granular view of program execution
Helps identify exact location of bugs
Options: Step Into, Step Over, Step Out
📝 Breakpoints
Markers set at specific lines of code
Program execution pauses when reaching breakpoint
Allows inspection of program state at that point
Variable values and expressions can be checked
Multiple breakpoints can be set throughout code
📝 Variable Watch Window
Monitor values of specific variables during runtime
Observe values change as program executes
Valuable for diagnosing variable-related issues
Can add/remove variables to watch
📝 Report Window
Shows contents of variables and expressions at breakpoints
Displays error messages and warnings
Shows detailed error descriptions and code locations
7. Additional IDE Features
7.5 Other Important IDE Features
📝 Source Code Editor
Integrated text editor for writing and editing programs
No need to use separate text editor
Speeds up development process
📝 Auto Indent
Automatically indents code when starting new line in code block
Commonly used in selection and iteration constructs
Maintains consistent code formatting
📝 Error Message List
Displays collection of errors, warnings, and messages
Detailed error descriptions and relevant code locations
Enables systematic error correction
📝 Stack Contents
Inspect contents of program's call stack during debugging
Shows order of function calls
Displays parameters and local variables of each function
📝 Auto-documenter
Explains function and purpose of programming code
Generates documentation automatically
📝 Crash Dump/Post-Mortem Report
Generated when program crashes
Captures program state and memory contents at time of crash
Helps diagnose root cause after program terminates unexpectedly
📌 IDE Features Summary
Category
Features
Coding
Context-sensitive prompts, Autocomplete, Auto indent
Error Detection
Dynamic syntax checks, Error highlighting
Presentation
Prettyprinting, Expand/collapse code blocks
Debugging
Single stepping, Breakpoints, Watch window, Report window
8. Glossary
📖 Key Terms
Assembler → Translates assembly language (low-level) into machine code
Assembly Language → Low-level language using mnemonics to represent machine instructions
Bytecode → Intermediate code produced by partial compilation (e.g., Java .class files)
Compiler → Translates entire high-level language program into machine code before execution
Debugging → Process of finding and correcting errors in a program
Breakpoint → Marker in code where program execution pauses during debugging
IDE → Integrated Development Environment - software for writing, editing, and debugging code
Interpreter → Translates and executes high-level language line by line
JIT Compilation → Just-In-Time compilation - compiling code during execution for better performance
Machine Code → Binary instructions (0s and 1s) directly executable by the processor
Mnemonic → Symbolic representation of a machine instruction (e.g., ADD, MOV, SUB)
Object Code → Output from a translator - machine code ready for execution
Opcode → Operation code - the part of machine instruction specifying the operation
Prettyprinting → Automatic formatting and syntax highlighting of code
Single Stepping → Executing program one line at a time for debugging
Source Code → Program written in high-level or assembly language
Symbol Table → Table storing symbolic names and their corresponding addresses/values
Translator → Program that converts source code into machine code
Two-Pass Assembler → Assembler that scans source code twice to build symbol table and generate code
Virtual Machine → Software that simulates a computer, allowing bytecode execution (e.g., JVM)
9. Exam-Style Questions
1. Describe the difference between a compiler and an interpreter. [4 marks]
Answer:
A compiler translates the entire source code into machine code before execution, creating an executable file
An interpreter translates and executes source code line by line, without producing an executable file
Compiled programs run faster but require recompilation after changes
Interpreted programs run slower but are easier to debug and develop
Compilers show all errors after compilation; interpreters stop at first error
Additional point: Compilers are used for finished programs; interpreters are used during development
2. Explain the purpose of a symbol table in a two-pass assembler. [4 marks]
Answer:
A symbol table stores symbolic names (labels) used in the assembly program
It records the corresponding memory address for each symbol/label
Built during the first pass of the assembler
Used in the second pass to resolve forward references
Allows symbolic addresses to be replaced with absolute addresses
Additional point: Helps handle labels like LOOP, START, END by mapping them to addresses
3. Jennifer uses an IDE to write her computer program. The IDE allows her to use both an interpreter and a compiler. Describe how Jennifer can use both a compiler and an interpreter while developing the program. [4 marks]
Answer:
Using Interpreter: Use an interpreter while writing the program to test/debug the partially completed program
Errors can be corrected and processing continue from where execution stopped
Errors are identified one at a time, making debugging easier
Using Compiler: Use the compiler after the program is complete
To create an executable file for distribution
To test the completed section repeatedly without re-interpreting every time
Additional point: Compiler not needed at runtime, only the executable
4. Explain what is meant by mixed mode translation, using Java as an example. [5 marks]
Answer:
Mixed mode translation combines compilation and interpretation
Source code is partially compiled into intermediate code (bytecode)
This bytecode is not specific to any processor/platform
Bytecode is then interpreted by a Virtual Machine (JVM for Java)
JVM can be installed on any platform (Windows, Mac, Linux)
Same bytecode file can run on any machine with JVM installed
Additional point: JIT compilation can further improve performance by compiling frequently-used bytecode to machine code
5. Describe two features of an IDE that help with debugging. [4 marks]
Answer:
Breakpoints: Markers set at specific lines where execution pauses, allowing inspection of variable values at that point
Single Stepping: Execute program one line at a time to identify exact location of errors
Watch Window: Monitor values of specific variables during execution to see how they change
Report Window: Shows contents of variables and expressions at breakpoints
Additional point: Stack contents shows order of function calls and local variables
Additional point: Error message list displays detailed error descriptions with code locations
9. Exam-Style Questions (Continued)
6. Explain why assembly language programs are described as "machine dependent". [3 marks]
Answer:
Assembly language uses mnemonics that are specific to a particular processor
Each processor architecture has its own set of instructions and mnemonics
Programs written for one processor cannot run on a different processor architecture
They are not portable from one type of computer/chip to another
Additional point: For example, x86 assembly differs from ARM assembly
7. Describe the difference between a one-pass and a two-pass assembler. [4 marks]
Answer:
One-pass assembler performs the entire conversion in a single scan
Puts machine code instructions straight into computer memory
Cannot easily handle forward references (symbols used before definition)
Two-pass assembler scans the source code twice
First pass builds symbol table with labels and addresses
Second pass resolves all references and generates final machine code
Additional point: Two-pass is more flexible and handles forward references properly
8. Discuss the advantages and disadvantages of using a compiler compared to an interpreter for distributing a program to users. [6 marks]
Answer:
Compiler Advantages:
Users only need the executable file, not the compiler or source code
Source code is not distributed, protecting intellectual property
Executables run faster as translation is already done
No extra setup or cost for users (no need for translation software)
Compiler Disadvantages:
Compiled code is platform-specific, may need different versions for different systems
Could potentially contain viruses (users can't verify source)
Interpreter Advantages:
Users have access to source code and can modify or extend the program
Same source code can run on any machine with an interpreter
Interpreter Disadvantages:
Users need the interpreter to run the program
Slower execution as code is translated each time
Developers lose control over code (can't charge for upgrades easily)
9. Describe two features of an editor in an IDE that can help a programmer to write program code. [4 marks]
Answer:
Feature 1: Context-sensitive prompts/autocomplete
Displays hints or choice of keywords appropriate at current insertion point
Shows available identifiers and functions that might be appropriate