JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
Gallery
Software Design and Development
Software Design and Development
Week 4
Week 5
Week 6
Week 7
Week 8
More
Share
Explore
Week 6
Learning Preparation
Translation
What is translation?
Why does it occur?
Computers cannot understand source code
^^ are you deadass
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.
Lexical Analysis Table
Lexical Analysis Table
Token
Type
Token
Type
1
&
VARIABLE
2
@
BEGIN
3
#
END
4
$
IF
5
?
THEN
6
{}
ELSE
7
[]
ENDIF
8
<>
OPERATOR
9
::
GET
10
()
PRINT
11
%
CONSTANT
12
!!
STRING
There are no rows in this table
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
What does the CPU do?
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
ALU
Arithmetic logic unit: All mathematical computations (eg. addition, multiplication, comparisons)
Control Unit
Ensures the fetch-execute cycle is working correctly
Accumulator
Storage register associated with the ALU, stores the results of instructions during processing
Program Counter
Holds the address of the next instruction
Register
Storage location used for temporary data storage
Hierarchy of Code Translation
What is machine code?
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
Machine Code Diagram
Machine Code Diagram
Each instruction (binary sequence) has TWO parts:
1001
101011011 1110
OPCODE, and OPERAND
Opcode
The instruction
eg. COPY
Operand
Two distinct parts: Memory Address and Data
Fetch-Execute Cycle
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
Ctrl
P
) instead.