Translation
Why does it occur?
Computers cannot understand source code Translation Process
Interpreter
Source code is translated line by line and executed immediately If errors exist they will cause an immediate halt Compilation
Known as ‘Batch Processing’ An entire executable file is created All errors are recorded and sent at the end Changes require a full recompilation Incremental Compilation
The aim is to reduce the time spent recompiling Incremental compilers aim to redice the translation time by only recompiling those parts of code that have changed since the last compile took place Lexical Analysis
Requires the source code to be read one character at a time Each character is scanned and redundant characters such as remarks, spaces, and indentation are removed. Variables, constants, operators, strings of text, and control structures are labelled with a token. Most translators have a token dictionary. Given the following source code:
BEGIN
Get Number
IF Number > 10 THEN
Print OK
ELSE
Print No
ENDIF
END
The tokens would be:
@
::&
$&<>%?
()!!
{}
()!!
[]
#
Syntactical Analysis
Tokens are then passed through the syntactic analyser to determine the logic of the code The syntactic analysis involves an examination of whether the identified elements in the statements are legal according to the syntax of the language The process is best understood by a parse tree Role of the CPU
Why Study the CPU?
What does it do?
Is the brains of the computer. Reads and executes program instructions Performs calculations and makes decisions (processing) Also responsible for the detection of syntax and run-time errors within programs Components of the CPU
Arithmetic logic unit: All mathematical computations (eg. addition, multiplication, comparisons) Ensures the fetch-execute cycle is working correctly Storage register associated with the ALU, stores the results of instructions during processing Holds the address of the next instruction Storage location used for temporary data storage Hierarchy of Code Translation
Main Points
The process of translating high-level code into machine code. Machine code is a collection of machine language instructions. Each instruction is in binary. A machine language instruction typically translates into one or more microcode instructions. This is Assembly language. Machine Code
Each instruction (binary sequence) has TWO parts:
1001 101011011 1110
OPCODE, and OPERAND
Two distinct parts: Memory Address and Data Fetch-Execute Cycle