0% found this document useful (0 votes)
37 views38 pages

ENGR112 - Lecture 2

Uploaded by

mmhygbwsvg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views38 pages

ENGR112 - Lecture 2

Uploaded by

mmhygbwsvg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Computer Architectures and History

of Programming Language

The Big Picture


What is a Computer
n An electronic machine that:
n Receives inputs
n Processes and manipulate the inputs data with high
speed and high accuracy
n Store these data and retrieve them whenever it is
necessary
n Produce outputs
n This is done by the interaction and collaboration
between the H/W components and the S/W
components
Computer System
Computer System

Hardware Software

OS Applications Translator
CPU I/O devices Memory

ALU RAM Machine


Languages Assembly High Level

CU ROM
Compiler

Registers 2nd Memory


Assembler
Interpreter
Hardware Components
n Input/Output devices
n keyboard, mouse, scanner/monitor, printer
n Storage Devices
n Memory
n Short-term storage for CPU calculations
n CPU
n ALU
n Control Unit
n Interface Unit
Hardware Components
Memory
n Memory provide rapid access with relatively low
capacity
n Data and instructions are stored in main memory
as a sequence of 0’s and 1’s called Bits (Binary
Digits)
n Byte (8 Bits)
n Each memory location consists of one Byte
n The address is just a number (in hex) to identify the
memory location
Memory
Memory (main memory)
n RAM (Random Access Memory)
n CPU fetches program instructions from RAM directly
(temp saves the data)
n The place where OS, application programs and the data
in current use are kept
n Has relatively low capacity
n Expensive
n Volatile
n ROM (Read Only Memory)
n Non-volatile
n The place where critical programs are kept such as
BIOS
Memory (Secondary Storage)
n Memory storage Devices:
n Hard disk
n CD-ROMS
n Advantages
n Long-term and high capacity storage than RAM or
ROM
n Non-volatile
n Less expensive than RAM
n Disadvantages
n Slower than RAM
Central Processing Unit (CPU)
n CPU is the “brain”
n Fetch – Decode – Execute
n ALU: arithmetic/logic unit
n Performs arithmetic and logical operations
n CU: control unit (supervisor)
n Controls all operations such as input, the sequences
of processing instructions and output
n Controls movement of data within the CPU
n Interface unit and Registers
n Interface Unit moves instructions and data between
the CPU and other hardware components
Computer System
Computer System

Hardware Software

OS Applications Translator
CPU I/O devices Memory

ALU RAM Machine Assembly High Level


Languages language languages

CU ROM
Compiler

Registers 2nd Memory


Assembler
Interpreter
Software Components
n Applications (Office, IE, Firefox, Games)

n Operating System OS (Linux, FreeBSD, Windows)


n Set of programs that lies between applications
software and H/W devices (provides services: file
management system, drivers, security)
n Controls and manages the computing resources

n Translators (compiler for C and C++, Compiler


and Interpreter for Java)
Programming Languages
n Machine Languages (Low Level Language)
n The language your computer directly understand
n Consists of 0’s and 1’s
n Each instruction is represented by a set of binary
digits
n Machine dependent (Intel, Mac, Motorola)
n Examples

100100 010001 //Load


100110 010010 //Multiply
100010 010011 //Store
Programming Languages
n Assembly Languages
n The language that is more understandable by human
n English-like abbreviations to represent the instruction
called mnemonic
n Needs assemblers to convert them to machine
language
n Example
ADD r1,10
LOAD r2,x
CMP r1,r2
JMP 04003F3
Machine and Assembly Languages
Description of the
Opcode hex. Operation Mnemo.
End of program
0000 Halt. execution HLT
0001 Load operand to accumulator LOA
accumulator at
0010 Store designated address STI
0011 Add operand to accumulator ADD
operand from
0100 Subtract accumulator SUB
operand with
0101 Multiply accumulator MUL
0110 Divide accumulator by operand DIV
0111 Unconditional jump JMP
1000 Jump if accumulator = 0 JEZ
1001 Jump if accumulator > 0 JGZ
1010 Jump if accumulator < 0 JLZ
1100 Stack commands -
1101 Jump to subroutine JSR
1110 Return from subroutine RET
1111 Index commands -
Programming Languages
n High Level Languages: C, C++, Java, Python and
Matlab
n Understandable to human
n Uses common mathematical operations (+,-,*,/)
n Single statements to perform substantial tasks
n Fewer lines of code than Assembly language to
perform a similar task
n Uses compilers/Interpreter and linkers
n What is the difference between compilers and
interpreters?
Summary
Machine binary language Low-level assembly High-level
Translators
n The computer does not understand your
language
n After you write your code in C++ to generate the
source code
n The original program in a high level language

n Compilers (for C/C++)


n Convert high-level language to machine language
How to Translate?
n Compiler will check for errors
n Syntax errors
n Violation of the syntax (grammar rules) of
programming language
n The only error that the compiler will check for
n Run time errors
n E.g. Division by Zero
n Logic errors
n Written correctly, Compiled Correctly but doesn’t run correctly
How to Translate?
n Object code
n The translated version in machine language
n Contains markers that indicates missing pieces that depends on.
n Contains machine instructions and information of how to load the
program into memory

n A Linker combines
n The object code for the programs we write
and
n The object code for the pre-compiled routines

into
the machine language program the CPU can run
How to Translate?
What is a program
n A set of ordered instructions to perform certain
task

n Steps for writing a program


n Problem Analysis : Define the problem
n What is input(s), output(s), process
n Design a solution (algorithm and flowchart)
n Program Implementation (coding)
n Program Compiling
n Program Execution and testing
What is a program: Example
Being an expert in programming, a math
instructor contacts and asks you to design
a software that solves a first order
equation.
What is a program: Example
(cont)
Problem analysis:
First order equation: ax + b =0
Output x : the solution
Input: a and b: two real numbers
Process: solve the equation:
x = -b/a
What is a program: Example
(cont)
Design the solution: The algorithm
1. Ask the user to enter a and b

2. Read a and b

3. Compute x = -b/a

4. Display x
What is a program: Example
(cont)
n Program Implementation (coding)
n Program Compiling
n Program Execution and testing

We will see these


later
C++ History
n Derived from C language
n C language is developed in 1971 by Dennis
Ritchie at Bell labs, alongside with UNIX
operating
n Added data types (int, float, double) in comparison to
previous languages
n Benefits: economize memory space and increase the
speed of execution the program
n H/W independent
n Portable Programs
C++ History
n C++ Developed at AT&T Bell Labs by Bjarne
Stroustrup in the 80’s
n Overcome several shortcomings of C
n Designed for the UNIX system environment
n Provides capabilities for object-oriented
programming (OOP)
n Objects: reusable S/W components that model the

real life items


n OOP easy to understand, correct and modify

n Why “++”
n C++ means: new C= old C + 1
Why C++?
n Not So Good News:
n C++ needs a lot of practice to learn

n Good News:
n Lots of good-paying jobs for programmers
n Many problems can be solved in different ways
n C++ allows a programmer to express their ideas at a
high level as compared to assembly languages
n C++ is widely used and taught
Who Uses C++?
n Computer makers such as Sun, SGI, IBM, and HP
n MongoDB (Big Data NoSQL database)
n Computer chip manufacturers (Motorola, Intel)
n Software companies
n Banks
n Telecommunications
n Universities
n http://www.stroustrup.com/applications.html

You might also like