You are on page 1of 28

CMP 131

Introduction to Computer
Programming
Violetta Cavalli-Sforza
Week 1, Lecture 2

28-February-2007 CMP 131 Introduction to Computers and Programming 1


Outline of Topics
• Review briefly last class
• More details about hardware
• Software/Hardware interface
– Data and program representation
– Machine arithmetic

28-February-2007 CMP 131 Introduction to Computers and Programming 2


Last Class
• Course Description
• Logistics
• Assessments (Grading)
• Homework
– First assignment will come out Monday

28-February-2007 CMP 131 Introduction to Computers and Programming 3


Last Class (2)
• Computers: What’s in them?
– Hardware
– Software
• Hardware devices
• Computers through time
• Hardware trends
• Hardware/software trends

28-February-2007 CMP 131 Introduction to Computers and Programming 4


Why Take This Course?
• Be more familiar with PCs
• Have a basic understanding of programming and the
programming process
• Develop critical thinking & problem solving capabilities
• Learn other programming languages faster & easier

28-February-2007 CMP 131 Introduction to Computers and Programming 5


Why Pascal?
• One of the first structured programming
languages
• It influenced the design of its successors
– Modula 2, Oberon (by N.Wirth)
– Modula2+, Modula3 (DEC, Olivetti)
– Java
– Not C or C++

28-February-2007 CMP 131 Introduction to Computers and Programming 6


Today’s Lecture
• Review of computers and hardware
– Some more information
• More about software
• Programming languages
– Low and high-level languages
– Viewing programming through different
languages
• Introduction to the Pascal IDE
environment
28-February-2007 CMP 131 Introduction to Computers and Programming 7
Computer Systems
• Computers
– Devices for performing computations at high
speeds with great accuracy
– A machine that can be programmed to
manipulate symbols. Can perform complex &
repetitive procedures quickly, precisely and
reliably. Can quickly store and retrieve large
amounts of data.

• Program
– A set of instructions for a computer to follow,
written in specific programming language

28-February-2007 CMP 131 Introduction to Computers and Programming 8


Computer Systems
• Hardware (HW)
– Actual physical machines (equipment)
that make up the computer
• Software (SW)
– A collection of programs used by a
computer
– A set of instructions provided by the
programmer that the computer follows.
– Program instructions have to be stored
in main memory before they can be
executed.
28-February-2007 CMP 131 Introduction to Computers and Programming 9
Computer Systems
• Computer Categories:
– Microcomputers (Personal computers / PCs)
• Used by a single person
– Workstations:
• Largest microcomputers
– Minicomputers:
• Can be used by many people simultaneously by using
several terminals connected to the same CPU
– Main frame computers:
• Faster & larger than minicomputers
– Super computers:
• Most powerful mainframe computers
• Of which category is you computer at home??

28-February-2007 CMP 131 Introduction to Computers and Programming 10


Hardware (HW): Organization
• Computer HW usually consists of:
– CPU
– Main memory (RAM & ROM)
– I/O Devices
– Secondary Memory
• CPU & main memory are the heart of the computer
• Usually the CPU, main memory and secondary memory are
housed in a single cabinet
I/O Devices
CPU
Secondary
Memory
Main Memory
28-February-2007 CMP 131 Introduction to Computers and Programming 11
Hardware (HW):
Central Processing Unit (CPU)
• Executes programs
• Performs calculations
– Arithmetic
• Add, subtract, divide, multiply, … etc.
– Logical
• Compare, test for true/false
• Controls & coordinates the other parts of
the computer.

28-February-2007 CMP 131 Introduction to Computers and Programming 12


Hardware (HW): Memory
• Main (Primary) Memory:
– Ordered sequence and specific number of memory
locations (Bytes, words) that have unique addresses
indicating their relative positions
– Fast, expensive, short term memory
– Holds intermediate results and serves as “scratch
paper”
– Needed to carry out program instructions
– Types:
• RAM: Random Access Memory
(vs. Sequential Access Memory)
• Volatile (i.e. contents disappear when the computer is switched
off)
• Writable (except where forbidden by the software)
• ROM: Read Only Memory
• Non-volatile
• Also usually random access

28-February-2007 CMP 131 Introduction to Computers and Programming 13


Hardware (HW): Memory
• Secondary (auxiliary) memory
– Used for keeping a permanent records of
information
– Holds programs and data between jobs
– Keeps data or program files for later use
– Slower, cheaper, long-term memory
– Common forms
• Diskettes, magnetic tapes, hard disk, CD-ROM’s,
DVD
– Some types are removable

28-February-2007 CMP 131 Introduction to Computers and Programming 14


Hardware (HW)
• I/O (Input/Output) devices
– Allow the user to communicate with the
computer.
– A single computer could be connected to
more than one input or output device.
– Examples:
• Input: Keyboard, mouse, scanner, voice
• Output: Screen, printer, voice

28-February-2007 CMP 131 Introduction to Computers and Programming 15


Hardware/Software
Architectures
• Mainframe Era
– 1940’s-70’s: mainframe computer,
minicomputers
– Environments:
• Batch environments, batch processing
– Files are basis for I/O: fixed formats, minimal device I/O
– Error recovery
– Lack of timing constraints
• Interactive environments
– Terminal and file I/O:
– Interactive error handling
– Faster performance

28-February-2007 CMP 131 Introduction to Computers and Programming 16


• Personal Computers Era
– 1978: the Apple II ran BASIC
• Educational use
– 1981: IBM released the first PC
– 1984: Macintosh
– Window environments:
• OO models are ideal (Smalltalk)
• Must interact with many I/O devices (file I/O is less
important)
– Embedded systems
• Error handling
• Real-time response
• Distributed systems with concurrently running tasks

28-February-2007 CMP 131 Introduction to Computers and Programming 17


• Networking Era:
– LANs (Local Area Networks):
client-server model
• Airline reservations, banking
– Internet
• 70’s: ARPANET: telnet, FTP, SMTP protocols
• late 80’s: HTML and HTTP added
– Issues and Effects:
• Static web pages with URLs for access
URL = Uniform Resource Locator
• Dynamic web pages for e-commerce (Perl, JAVA, etc.)
• Security
• Performance (multiple clients)
– Offloading work to client

28-February-2007 CMP 131 Introduction to Computers and Programming 18


Hardware/Software Concepts
• Computers manipulate instructions and data
– Represented in similar ways
– Used in different ways
– Representation is binary (digital hardware is binary)
• Numbers vs. symbols
– Computers represent everything as numbers
– But numbers can represent symbols
– Can perform “symbolic” computation
• Beginning of Artificial Intelligence

28-February-2007 CMP 131 Introduction to Computers and Programming 19


HW/SW Concepts: Data
 What is it?
 Numbers, characters, images, or other method of recording
 Can be assessed by a human or (especially) input into a computer,
stored and processed there, or transmitted on some digital channel.
 Nearly always represent data in binary.
 Has no meaning on its own.
 When interpreted by data processing system it takes on meaning and
becomes information.
 Storage
– Setting of individual bits to specific values, destroying its previous
contents
 Retrieval
– Copying the contents of a particular memory cell to another storage
area.
– Original data remains unchanged

28-February-2007 CMP 131 Introduction to Computers and Programming 20


HW/SW Concepts: Representation
• Digit / Bit
– Smallest unit of information/storage, sufficient
to hold one bit
– Can take one of two values
(true/false, 1/0, or yes/no)
– Corresponds to an input/output being on or off
• Byte
– Smallest addressable unit of storage
– Usually 8 bits
– Typically holds one character
– Can represent 256 different values
28-February-2007 CMP 131 Introduction to Computers and Programming 21
HW/SW Concepts: Representation
• Word
– Fundamental unit of storage in a computer
– Word size is one of its chief distinguishing
characteristics of a computer
– Typical size in modern computers: 32 bits (4
bytes) or 64 bits (8 bytes)
– An instruction is usually one or more words
long
– A word can be used to hold a whole number
of characters

28-February-2007 CMP 131 Introduction to Computers and Programming 22


Decimal Number System
• A base 10 system
• Each digit position can hold 10 values
(0-9)
Ex. 1234
= 4*1 + 3 * 10 + 2*100 + 1*1000
= 4*100 + 3 * 101 + 2*102 + 1*103

28-February-2007 CMP 131 Introduction to Computers and Programming 23


Binary Number System
• A base 2 system
• Each digit position can hold 2 values (0-1)
Ex. 1011
• Decimal conversion
– Equals: 1*20 + 1*21 + 0*22 + 1*23
– Equals: 1 + 2 + 0 + 8 = 11
• Maximum number of values in 4 bits: 16
– 0 to 15
• Maximum number of values in 8 bits: 256
– 0 to 255 [or -128 to 127]
– This is how much you can store in a byte

28-February-2007 CMP 131 Introduction to Computers and Programming 24


Binary Numbers
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 10
1011 11
1100 12
1101 13
1110 14
1111 15
28-February-2007 CMP 131 Introduction to Computers and Programming 25
Binary Addition
1010 + 10 + 1010 + 10 +
0101 = 5= 0011 = 3 =
--------- ------ --------- ------
1111 15 1101 13

1010 + 10 +
0111 = 7=
--------- ------
0001 17 => 1 OVERFLOW!!!

28-February-2007 CMP 131 Introduction to Computers and Programming 26


Other Number Systems
• Hexadecimal: base 16
– Each digit can hold 16 values (0-9,A-F)
– Ex: A02F
– Decimal conversion?
– Note: 1 hex digit = 4 binary digits
• Octal: base 8
– Each digit can hold 8 values (0 to 7)
– Ex: 127
– Decimal conversion?
28-February-2007 CMP 131 Introduction to Computers and Programming 27
Logical Operations
• AND:
– 1 AND 1 = 1
– Everything else = 0
• OR
– 0 AND 0 = 0
– Everything else = 1
• XOR (Exclusive OR)
– 0 AND 1 = 1
– 0 AND 0 = 0, 1 AND 1 = 0
28-February-2007 CMP 131 Introduction to Computers and Programming 28

You might also like