EE 344
Digital Computer Systems
Lecture 4: High-Level Language
Why HLL?
Shield programmers from detailed
machine-level specifications (hence
higher productivity)
Portability
Easy to upgrade (e.g. CC++->C#)
Main Characteristics
Usually translated by compilers
Except scripting languages (Perl, JavaScript, )
What an HLL programmer sees, depends
on the language at hand
Mostly data structures and operations
on those structures
Each data structure has a certain type
which determines
its characteristics
the operations that can be performed on it
Features Common to most HLL
Variables and Constants
Arithmetic/logic operators and assignment
Conditional statements and loops
Subroutines, procedures, or functions
IO streams and files
Application Programming Interface (API)
Variables and Constants
Allows the programmer to refer to data values symbolically by name
Type (for the compiler to allocate memory space)
Scope (when and where the variable is active)
storage class (determines the period the variable exists)
Data structure: array and structures
Declaration and initialization
Signed and unsigned integers
Floating points
Character
pointer
Global
local
Automatic (is the default for variables declared inside a block)
Static
dynamic
Control Structures
What distinguishes a computer from a
calculator
Used for making decisions and loops
Subroutines
Why do we need them?
Economy: decrease program size
Modularity: facilitate the programming
Functions and Procedures
Subroutine nesting and recursion
Libraries
IO Streams and Files
Program accepts external inputs, in
order to solve different instances of
the problem
The results must go somewhere
Programmers do not concern themselves
with any specific IO device
Files: opened, accessed, and closed
API (Application Programming
Interface)
Set of commands from the application
to the operating system
Simplifies the job of the application
programmer
Three classes of API commands:
IO Management
Memory Management
Process Management
How API Works
Different Paradigms
Imperative/Procedural (e.g. C)
a list of operations to do in order
Object Oriented (e.g. C++, Java)
groups of communicating bubbles
Functional (e.g. LISP)
Based on recursion
Logical (e.g. Prolog)
Based on symbolic logic
Compiler
Qualities of a Good Compiler
Correct: the meaning of sentences must be preserved
Robust: wrong input is the common case
compilers and interpreters cant just crash on wrong input
they need to diagnose all kinds of errors safely and reliably
Efficient: resource usage should be minimal in two
ways
the process of compilation or interpretation itself is
efficient
the generated code is efficient when interpreted
Usable: integrate with environment, accurate
feedback
work well with other tools (editors, linkers, debuggers, . . . )
descriptive error messages, relating accurately to source
Anatomy of a Compiler
Typical Phases of a Compiler
Lexical analysis
Syntactic analysis
Semantic analysis
Code generation (high/intermediate
level)
Optimization
Code generation (object file or machine
code)
X = 3.14 * (9.0 +Y)
X = 3.14 * (9.0 +Y)
<ID,x>, EQ, <FLOAT,3.14>, STAR, LPAR, <FLOAT,9.0>, PLUS, <ID,y>, RPAR
X = 3.14 * (9.0 +Y)
10
X = 3.14 * (9.0 +Y)
11
Is X and Y of compatible type?
Is this type compatible with the constants?
12
13
Example
14
Example: Lexical Analysis
Example
15
Example: Syntactic Analysis
Example
16
Example: Semantic Analysis
Example: IR (intermediate
representation)
17
Example: IR optimization
IR
Optimized IR
Example: Assembly Language
Generation
18
MIPS Instruction Set
Used as an example throughout the text book
Stanford MIPS commercialized by MIPS Technologies
(www.mips.com)
A discussion of MIPS can be found on Wikipedia
(http://en.wikipedia.org/wiki/MIPS_architecture)
Decent share of embedded core market
Applications in consumer electronics, network/storage
equipment, cameras, printers,
Typical of many modern ISAs
See MIPS Reference Data tear-out card from your textbook,
and Appendixes B and E on the course web page
19
See You in the Assembly
Language Level!
20