You are on page 1of 16

Chapt.

2 Machine Architecture
Impact of languages
Support faster, more secure
Primitive Operations
e.g. nested subroutine calls Subroutines implemented with stack (ex: PL/1- recursion)

IBM704 index registers Security


e.g., data and code kept separate O.S. kept separate

Limitations
Space Time

Networks, multiprocessors, etc.

Hardware or actual computer


Data / storage CELL
Main memory, cache and registers Fixed-length words determines range of values of data
Limitation on range and precision of numbers

Strictly speaking, built-in types are determined by operations

Operations on data
Primitive operations manipulate data Integer, character, bit string, (1-dimensional) arrays Possibly floating-point, character string Data operations are valid on all data cells

Hardware
Sequence control (control operations)
Sequence (von Neumann architecture)
Program address register (PC) incremented automatically

Jump or branch Branch conditionally Multiprocessing as alternative control mechanism

Data access
Operation (move, load, etc.) Operand typically address of cell

RISC (fewer hardware ops) vs CISC

Hardware
Effect of current access times
Register access 5-10 nsec Memory access 50-70 nsec I/O access 10-15 msec.

Modular programs can make efficient use of cache and virtual memory (hits) Cost of tasking In-line modules Multi-dimensional arrays

Computer states
State transitions for representing virtual machine State transition diagrams for proving correctness

Role of firmware
Instructions in microprogram Emulation to create virtual computer FORTRAN hardware machine
Statements in hardware/firmware

Translator is interpreter Cost in terms of flexibility, monetary, speed


Slower for running spreadsheet, for example

Translators
Translators allow for the creation of virtual machines A program language defines its own machine
May restrict data operations
e.g., pure LISP does not have use floating point operations

May restrict control operations


Typically does not allow use of primitive i/o operations

Adds its own data and control structures

Translators
Interpreter decodes and executes each hardware machine instruction or higher level statement (initially Basic, Snobol, LISP, Perl, Smalltalk, Java)
Does not create object code Each statement (even in a loop) must be repeatedly translated

Assembler specific to hardware; translates almost 1-1 to hardware machine instruction

Translators
Virtual machine is portable, user friendly(?)
Compiler creates object code in assembler or hardware machine language Quick and dirty Optimizing Cross compiler translates to machine language of another machine (simulation) Useful for designing code for small chips Load or link editor - source code is typically relocatable and object code is a single executable program with external references resolved Preprocessor or macroprocessor Source and object code both in high level language Initial pass for expanding macros, constants, C++, etc.

Hierarchies of virtual machines


Hardware machine- gates, switches Augmented by microcode Operating System virtual machine
Denies some functions Adds some capabilities
e.g., i/o, semaphores

C virtual computer
Hides/ adds capabilities C library routines

Web virtual machine


Browser executing HTML, XML pages

Binding Times
Binding of data: association with cell(s) Binding of operation: association with hardware primitive operation(s) Typically several intermediate steps Flexibility versus efficiency/ reliability
Late binding provides greater flexibility, less efficiency, typically less reliability

Binding Times
During program execution
Module entry- semi-dynamic Arbitrary run times dynamic

During compile/ translation time


Bindings chosen by the programmer
Ex: types and their operations Array and record size

Bindings chosen by the translator


Ex: position of data on the stack

Bindings chosen by the loader, linker


Ex: storage location or displacement

Binding Times
During language implementation for specific hardware
possibly number implementation
Cs int Issue of portability

During language definition type


The ability to define more operations for a type The ability to define new data types

Binding Times: example


Statement X = X + 10
Association of Type with X
Language definition determines possible range of types (int, short int, float, complex, user defined, etc.) Xs type may be chosen statically (C), or dynamically (SNOBOL)

Association of Value with X


Language implementation may determine range and representation of value Xs value is determined at arbitrary pts of execution

Association of +
Language definition determines what + can be (or sum, etc.) Binding of + to hardware or software op Compile time in FORTRAN, C At arbitrary pts of execution in C++ polymorphism

Binding time: example


static int X = 10;
In C
Xs range of types, meaning of = are determined at language definition X is assigned 10 only upon first execution X retains value between calls

Do we need to know about the hardware?


High speed, large memories shield us from many of the problems that earlier programmers had Speed of translating and executing Java is small in relation to network transmission, user response time Can careful language design shield us from hardware? not entirely