CPS 125: Digital Computation and Programming Week 1: Overview of Computers and Software.

46
CPS 125: Digital CPS 125: Digital Computation and Computation and Programming Programming Week 1: Overview of Week 1: Overview of Computers and Software Computers and Software

Transcript of CPS 125: Digital Computation and Programming Week 1: Overview of Computers and Software.

CPS 125: Digital Computation CPS 125: Digital Computation and Programmingand Programming

Week 1: Overview of Computers and Week 1: Overview of Computers and SoftwareSoftware

Why do engineers study Why do engineers study programming?programming?

Benefit Benefit from the ability to write their own programsfrom the ability to write their own programs

Problems inevitably arise that are outside the range of Problems inevitably arise that are outside the range of problems solvable by the application software to which problems solvable by the application software to which an individual engineer/scientist has immediate access.an individual engineer/scientist has immediate access.

CriticalCritical Expanding society‘s technical knowledge Expanding society‘s technical knowledge Applying the principles of science and Applying the principles of science and

mathematics to society’s problems, overlooking mathematics to society’s problems, overlooking the limitations of a software the limitations of a software

ComputerComputer

exists almost every where in our living exists almost every where in our living environmentenvironment

From refrigerators, coffee machines, cars, stereos, From refrigerators, coffee machines, cars, stereos, mp3s, cell phones, boats, toys, …mp3s, cell phones, boats, toys, …

A modern car contains about 50 microprocessorsA modern car contains about 50 microprocessors If you've got a late-model luxury sedan, two or three If you've got a late-model luxury sedan, two or three

processors might be obvious in the GPS navigation processors might be obvious in the GPS navigation system or the automatic distance control. system or the automatic distance control.

The current 7-Series BMW and S-class Mercedes boast The current 7-Series BMW and S-class Mercedes boast about 100 processors apiece.about 100 processors apiece.

Computer in twenty-first centuryComputer in twenty-first century

Important hint:Important hint:

Learning programming is an essential to be a Learning programming is an essential to be a professional engineer for all fields.professional engineer for all fields.

OutlineOutline

What Is a Computer?What Is a Computer? Computer ComponentsComputer Components Computer SoftwareComputer Software Software Development MethodSoftware Development Method

What Is a ComputerWhat Is a Computer

Computer:Computer:An electronic machine that can receive, store,An electronic machine that can receive, store,transform, and output data of all kindstransform, and output data of all kinds

numbers, text, images, graphics, and sound, to numbers, text, images, graphics, and sound, to name a few.name a few.

Conceptual Layers of a Computer SystemConceptual Layers of a Computer System Application programsApplication programs Operating systemOperating system Computer hardwareComputer hardware External connectionsExternal connections

What are “Machine Structures”?What are “Machine Structures”?

Coordination of many Coordination of many levels of abstractionlevels of abstraction

Digital Design

transistors

I/O systemProcessor

CompilerOperating

System(Windows 98)

Application (Netscape)

Circuit Design

Instruction Set Architecture

Datapath & Control

Memory

Software Assembler

Hardware

Computer ComponentsComputer Components

Central Processing Unit

Main Memory

ALU CU

CD

zipdisk

floppydisk

SecondaryStorage:

mouse

monitor

keyboardharddisk

printer

scanner

Input & Output Devices

Computer SystemComputer System

CPU + Main Memory ~ “core”CPU + Main Memory ~ “core” Secondary Storage + I/O Devices ~ “peripherals”Secondary Storage + I/O Devices ~ “peripherals” Bus ~ communication between componentsBus ~ communication between components

CPU Sec. Storage

I/O 1 I/O 2 I/O n

MemoryBus

Central Processing UnitCentral Processing Unit CPUCPU: the “brain” of a computer, transforms data from one to : the “brain” of a computer, transforms data from one to

another, another, understands and executes understands and executes computer programscomputer programs written in written in machine languagemachine language

The circuitry of a modern CPU consists of millions of The circuitry of a modern CPU consists of millions of miniature circuits manufactured in a sliver of silicon known miniature circuits manufactured in a sliver of silicon known as as Integrated CircuitIntegrated Circuit (IC) or (IC) or chipchip

MicroprocessorMicroprocessor: an entire CPU on a single chip: an entire CPU on a single chip

Arithmetic operations are performed using Arithmetic operations are performed using binary number binary number systemsystem where data and control information (instructions) where data and control information (instructions) uses only two basic symbols: “0”, “1” represented by uses only two basic symbols: “0”, “1” represented by electronics signalselectronics signals

Components of CPUComponents of CPU

Arithmetic/Logic UnitArithmetic/Logic Unit (ALU): (ALU): performs arithmetic operations (addition, subtraction, etc.) performs arithmetic operations (addition, subtraction, etc.)

and makes logical comparisons (and, or, equal to, etc.);and makes logical comparisons (and, or, equal to, etc.); Control UnitControl Unit (CU): (CU):

decodes machine instructions and sends control signals to decodes machine instructions and sends control signals to the other components to carry out the instructionsthe other components to carry out the instructions

RegistersRegisters: : high speed memory locations inside the CPU, used to store high speed memory locations inside the CPU, used to store

temporarily the current instructions and data valuestemporarily the current instructions and data values

QuestionQuestion

Which of the following statement is true?Which of the following statement is true? A). CPU + Main Memory ~ “core” of a computerA). CPU + Main Memory ~ “core” of a computer B). The CPU consists of :ALU,CU and RegisterB). The CPU consists of :ALU,CU and Register C). CU C). CU decodes machine instructions and sends codecodes machine instructions and sends co

ntrol signals to the other components to carry out tntrol signals to the other components to carry out the instructionshe instructions

D). D). RegistersRegisters are high speed memory located insid are high speed memory located inside the CPUe the CPU

E). All of the aboveE). All of the above

Question 2Question 2

The arithmetic and Logic UnitThe arithmetic and Logic Unit A). Decode instructionsA). Decode instructions B). Perform decision makingB). Perform decision making C). Performs arithmetic operationsC). Performs arithmetic operations D). All of the aboveD). All of the above E). C and B above E). C and B above

Binary NumbersBinary Numbers All information in a typical computer is All information in a typical computer is

represented in binaryrepresented in binary BitsBits: a binary digit (0 or 1): a binary digit (0 or 1) BytesBytes: 8 bits of data, which is the amount of : 8 bits of data, which is the amount of

memory required to represent one charactermemory required to represent one character Conversion from binary to decimalConversion from binary to decimal

bb7 7 bb66bb55bb44bb33bb22bb11bb0, 0, where bwhere bi i has place value 2has place value 2ii

Convert to decimalConvert to decimalbb77 * 2 * 277+b+b66*2*26 6 + b+ b55*2*25 5 +b+b44*2*24 4 +b+b33*2*23 3 +b+b22*2*22 2 +b+b11*2*21 1 + b+ b00*2*200

Example of Binary-Decimal Example of Binary-Decimal Conversion Conversion

124 in binary124 in binary Answer: 01111100Answer: 01111100

251 = ?251 = ? 10101011 in decimal10101011 in decimal

Answer: 171Answer: 171 01101111 = ? In Binary01101111 = ? In Binary

Negative binary numbersNegative binary numbers

2’s complement notation2’s complement notation In one's complement, positive numbers are In one's complement, positive numbers are

represented as usual in regular binary. However, represented as usual in regular binary. However, negative numbers are represented differently. To negative numbers are represented differently. To negate a number, replace all zeros with ones, and negate a number, replace all zeros with ones, and ones with zeros - flip the bits ones with zeros - flip the bits

Begin with the number in one's complement. Add Begin with the number in one's complement. Add 1 if the number is negative. 1 if the number is negative.

True or false?True or false?

Arithmetic operations are performed by CPU Arithmetic operations are performed by CPU using using binary number systembinary number system

MemoryMemory

The main memory is used to store the program and The main memory is used to store the program and data which are currently manipulated by the CPUdata which are currently manipulated by the CPU

The main memory is fast and of limited sizeThe main memory is fast and of limited size The most common memory type is random access The most common memory type is random access

memory (RAM)memory (RAM) The information stored in RAM will be lost when The information stored in RAM will be lost when

electrical power is removedelectrical power is removed ROMROM

Memory CellsMemory Cells

Memory: a collection of memory cellsMemory: a collection of memory cells Memory cellMemory cell

Memory cell can be randomly accessedMemory cell can be randomly accessed

Word

0000 0000 0100 0001

ContentsAddress

0000 0101

QuestionQuestion

Answer Ture/FalseAnswer Ture/False Every byte in memory has a unique address to be Every byte in memory has a unique address to be

accessedaccessed RAM: stand for Random Access Memory RAM: stand for Random Access Memory

can be read and written.can be read and written. ROM stand for Read Only MemoryROM stand for Read Only Memory RAM is used to store application programsRAM is used to store application programs ROM is used to install System routinesROM is used to install System routines

used for store the system BIOS and video BIOS used for store the system BIOS and video BIOS

Secondary StorageSecondary Storage

The secondary storage provides the long-term The secondary storage provides the long-term storage of large amounts of data and programstorage of large amounts of data and program

Before data and program in the secondary Before data and program in the secondary storage can be manipulated by the CPU, they storage can be manipulated by the CPU, they must first be loaded into the main memory must first be loaded into the main memory

The secondary storage is relatively slow and The secondary storage is relatively slow and of very large sizeof very large size

Secondary Storage DevicesSecondary Storage Devices

Magnetic DisksMagnetic Disks: thin platter of metal or : thin platter of metal or plastic on which data are represented by plastic on which data are represented by magnetized spots arranged in tracksmagnetized spots arranged in tracks Hard disksHard disks (attached to disk drives): many GB (attached to disk drives): many GB Floppy disksFloppy disks (removable): 1.44 MB (removable): 1.44 MB Zip disksZip disks (removable): 100 or 250 MB (removable): 100 or 250 MB

Secondary Storage DevicesSecondary Storage Devices

Optical DisksOptical Disks: silvery plastic platter on which : silvery plastic platter on which a laser records data as pits in a spiral track on a laser records data as pits in a spiral track on one side of diskone side of disk CD: 680 MB; DVD: 4.7 GB on one layer CD: 680 MB; DVD: 4.7 GB on one layer

Magnetic TapeMagnetic Tape: a sequential-access device (fo: a sequential-access device (for backup of data)r backup of data)

FileFile: named collection of data stored on disk: named collection of data stored on diske.g. c:\compons\ics\cpus\pent.txt (PC)e.g. c:\compons\ics\cpus\pent.txt (PC)

Data Storage HierarchyData Storage Hierarchy

Storage CapacityStorage Capacity

UnitsUnits AbbrevAbbrev..

Equivalent toEquivalent to Comparison to Comparison to Power of 10Power of 10

ByteByte BB 8 bits8 bits

KilobyteKilobyte KBKB 1024 (21024 (21010) bytes) bytes > 10> 1033

MegabyteMegabyte MBMB 222020 bytes bytes > 10> 1066

GigabyteGigabyte GBGB 223030 bytes bytes > 10> 1099

TerabyteTerabyte TBTB 224040 bytes bytes > 10> 101212

Input and Output DevicesInput and Output Devices

Provide interfaces for humans to communicate Provide interfaces for humans to communicate with computerswith computers

Input devicesInput devices Keyboards: type into textKeyboards: type into text Mouse, track balls, touch pads: pointing devices Mouse, track balls, touch pads: pointing devices

for input of position/selection datafor input of position/selection data Scanner: convert image to a grid of pixelsScanner: convert image to a grid of pixels

Output devicesOutput devices Monitor, printer, speaker, etc.Monitor, printer, speaker, etc.

NetworksNetworks

Groups of individual computers and peripheral Groups of individual computers and peripheral devices linked together to share information devices linked together to share information and resources.and resources. Local Networks (LAN)Local Networks (LAN) Wide Area Networks (WAN)Wide Area Networks (WAN)

InternetInternet Links machine throughout the worldLinks machine throughout the world

Connecting Computers: LANConnecting Computers: LAN

computer computer computer

B&W printer color printer

Local Area Network (LAN)

Connecting Computers: WANConnecting Computers: WAN

LAN

LAN

LAN

LAN

Computer SoftwareComputer Software Two Types of SoftwareTwo Types of Software

Operating SystemOperating System Application SoftwareApplication Software

Computer LanguagesComputer Languages Machine LanguageMachine Language Assembly LanguageAssembly Language High-Level LanguageHigh-Level Language

From Source-Code to Executable CodeFrom Source-Code to Executable Code

Operating SystemOperating System

Control and manage computer resourcesControl and manage computer resources Main functions:Main functions:

Communicating with computer usersCommunicating with computer users Managing allocation of computer resourceManaging allocation of computer resource Collecting input and conveying outputCollecting input and conveying output Accessing and writing to secondary storageAccessing and writing to secondary storage AuthorizationAuthorization

Widely used operating systemsWidely used operating systems UNIX, Windows, Macintosh OS, and OS/2, etc.UNIX, Windows, Macintosh OS, and OS/2, etc.

Application SoftwareApplication Software

Application software is the software that has made Application software is the software that has made using computers indispensable and popularusing computers indispensable and popular

Common application softwareCommon application software Word processorsWord processors SpreadsheetsSpreadsheets Database management systemsDatabase management systems Drawing programsDrawing programs

Learning how to develop application software is Learning how to develop application software is our focusour focus

Computer LanguagesComputer Languages

Machine LanguagesMachine Languages A collection of binary instructionsA collection of binary instructions Hard to understand by humans while the only Hard to understand by humans while the only

understandable language by computersunderstandable language by computers Specific to a particular type of CPUSpecific to a particular type of CPU

Assembly LanguagesAssembly Languages Operations are represented by mnemonics, Operations are represented by mnemonics,

variables are represented by names, so is more variables are represented by names, so is more readablereadable

Dependent on type of CPUDependent on type of CPU

Example of machine language codeExample of machine language code

000000 00001 00010 00110 00000 100000 000000 00001 00010 00110 00000 100000 100011 00011 01000 00000 00001 000100100011 00011 01000 00000 00001 000100 000010 00000 00000 00000 10000 000001000010 00000 00000 00000 10000 000001

adding the registers 1 and 2 and placing the result adding the registers 1 and 2 and placing the result in register 6 in register 6

Loading a value from the memory cell 68 cells Loading a value from the memory cell 68 cells after the one register 3 points to into register 8 after the one register 3 points to into register 8

Jumping to the address 1025 Jumping to the address 1025

Example of Assembly language codeExample of Assembly language code page 60,132page 60,132 TITLETITLE A07LOOP (COM) Illustration of LOOPA07LOOP (COM) Illustration of LOOP .MODEL SMALL.MODEL SMALL .CODE.CODE ORGORG 100H 100H A10MAINA10MAIN PROC NEARPROC NEAR MOVMOV AX,1 AX,1 ;Initialize AX and;Initialize AX and MOVMOV BX,1 BX,1 ; BX to 1,; BX to 1, MOVMOV CX,10 CX,10 ; CX for 10 loops; CX for 10 loops INCINC AX AX ;Add 01 to AX;Add 01 to AX A20:A20: ADDADD AX,BX AX,BX ;Add BX to AX;Add BX to AX MOVMOV BX,AX BX,AX LOOP A20LOOP A20 ;Decrement CX, ;Decrement CX, ; loop if nonzero; loop if nonzero MOVMOV AX,4C00H AX,4C00H ;End processing;End processing INTINT 21H 21H A10MAINA10MAIN ENDPENDP ENDEND A10MAIN A10MAIN

Computer LanguageComputer Language

High-Level LanguageHigh-Level Language Closer to the human way of expression Closer to the human way of expression Using higher-level of abstraction concepts from Using higher-level of abstraction concepts from

the application area for which it is intendedthe application area for which it is intended Independent of a given hardwareIndependent of a given hardware The downside: computers The downside: computers do notdo not understand high- understand high-

level languageslevel languages

High-Level LanguageHigh-Level Language

Language Application area Origin of name

FORTRAN Scientific programs Formula translation

COBOL Business dataprocessing

Common Business-Oriented Language

Lisp Artificial intelligence List processing

C System programs Successor of language B

Prolog Artificial intelligence Logic Programming

Ada Real-time systems Lady Ada Augusta Byron

Smalltalk Object-oriented (OO) Objects talk via messages

C++ System programmingwith OO support

Incremental modificationof C

Java Internet applications Good coffee!

Software Development CycleSoftware Development Cycle

Compile

Link

Library routines

Other object files

Think

Edit

Load

Execute

Source Program

Software Development MethodSoftware Development Method

1.1. Specify the Specify the problemproblem requirements requirements

2.2. AnalyzeAnalyze the problem the problem

3.3. DesignDesign the algorithm to solve the problem the algorithm to solve the problem

4.4. ImplementImplement the algorithm in a high-level the algorithm in a high-level computer languagecomputer language

5.5. TestTest and verify the completed program and verify the completed program

6.6. MaintainMaintain and update the program and update the program

An Example for Problem AnalysisAn Example for Problem Analysis

Problem statementProblem statement::Calculate and display the Calculate and display the volume of a cylindervolume of a cylinder given its given its base base

radiusradius and and height in centimetersheight in centimeters.. SummarizationSummarization

Problem inputsProblem inputs:: Radius of base of a cylinder (in centimeters)Radius of base of a cylinder (in centimeters) Height of cylinder (in centimeters)Height of cylinder (in centimeters)

Problem outputsProblem outputs:: Volume of cylinder (in cubic centimeters)Volume of cylinder (in cubic centimeters)

Relationship between input and outputRelationship between input and outputThe The formulaformula for the volume of a cylinder V= for the volume of a cylinder V= ππ rr22hh

DesignDesign

Algorithm: a list of instructions to solve a problemAlgorithm: a list of instructions to solve a problem Top-downTop-down design design

List major steps, or sub-problemsList major steps, or sub-problems Solve the sub-problemsSolve the sub-problems Algorithm refinementAlgorithm refinement

Basic algorithm for a programming problemBasic algorithm for a programming problemGet the data -> Perform the computations -> Display the Get the data -> Perform the computations -> Display the

resultsresults Desk checkDesk check

Implementation, Testing, and Implementation, Testing, and MaintenanceMaintenance

ImplementationImplementation: writing it as a program, : writing it as a program, which means converting each step into one or which means converting each step into one or more statements in a programming languagemore statements in a programming language

TestTest: testing the completed program to verify : testing the completed program to verify that it works as desired, with several runs and that it works as desired, with several runs and different sets of datadifferent sets of data

MaintenanceMaintenance: modifying program to remove : modifying program to remove undetected errors and to keep it up-to-dateundetected errors and to keep it up-to-date

Caution: Caution: Failure is part of the processFailure is part of the process

SummarizeSummarize

What Is a ComputerWhat Is a Computer Computer ComponentsComputer Components Computer SoftwareComputer Software Software Development MethodSoftware Development Method

Week1Week1

EndEnd