cse 1301 lecture 1 introduction figures from lewis, c# software solutions, addison wesley richard...

Post on 29-Mar-2015

217 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CSE 1301

Lecture 1

Introduction

Figures from Lewis, “C# Software Solutions”, Addison Wesley

Richard Gesick

CSE 1301 1A-2/54

Agenda• Hardware and Software• Analog & Digital• Binary and Data Representations• Introduction to Computer Architecture

CSE 1301 1A-3/54

Computer Processing• Hardware

– The stuff you can touch

• Software– Programs and data

CSE 1301 1A-4/54

CSE 1301 1A-5/54

Modern Computer

CSE 1301 1A-6/54

Hardware and Software• Hardware

– the physical, tangible parts of a computer– keyboard, monitor, disks, wires, chips, etc.

• Software– programs and data– a program is a series of instructions

• A computer requires both hardware and software

• Each is essentially useless without the other

CSE 1301 1A-7/54

Basic Computer Concepts• Hardware

– Central Processing Unit– Memory and Storage Devices

• Operating Systems• Application Software• Computer Networks and the Internet

CSE 1301 1A-8/54

Hardware• A typical computer consists of:

– CPU: executes the instructions of the program– Hard disk: stores instructions and data so

program can be loaded into memory and executed

– Memory unit: stores the program instructions and data while executing

– Keyboard and mouse: used for data input– Monitor: used to display output from a program– Other accessories / peripherals

CSE 1301 1A-9/54

CSE 1301 1A-10/54

CPU and Main MemoryCentral

ProcessingUnit

MainMemory

Chip that executes program commands

Intel Pentium 4Sun ultraSPARC IIIPrimary storage

area for programs and

data that are in active use

Synonymous with RAM

CSE 1301 1A-11/54

Secondary Memory DevicesCentral

ProcessingUnit

MainMemory

Floppy Disk

Hard Disk

Secondary memorydevices providelong-term storage

Information is movedbetween main memoryand secondary memoryas needed

Hard disksFloppy disksZIP disksWritable CDsWritable DVDsTapes

CSE 1301 1A-12/54

Input / Output DevicesCentral

ProcessingUnit

MainMemory

Floppy Disk

Hard Disk

Monitor

Keyboard

I/O devices facilitateuser interaction

Monitor screenKeyboardMouseJoystickBar code scannerTouch screen

CSE 1301 1A-13/54

The Central Processing Unit• A CPU is on a chip called a microprocessor • It continuously follows the fetch-decode-

execute cycle:

fetch

Retrieve an instruction from main memory

decode

Determine what theinstruction is

execute

Carry out theinstruction

CSE 1301 1A-14/54

The Central Processing Unit• The CPU contains:

Arithmetic / Logic Unit

Registers

Control Unit

Small storage areas

Performs calculations and makes decisions

Coordinates processing steps

CSE 1301 1A-15/54

Central Processing Unit (CPU)• Arithmetic Logic Unit: performs integer

arithmetic and logical operations• Floating-point Unit: performs floating-point

operations• Hardware registers: store data and memory

addresses• Instruction pointer: keeps track of current

instruction to execute• Examples: Intel Pentium 4, Sun

Microsystems SPARC, IBM PowerPC

CSE 1301 1A-16/54

Processor Instruction Set• Move data from one location to another• Perform a calculation• Change the sequence of instructions to

execute (the flow of control)

CSE 1301 1A-17/54

CPU Speed• Rated in MHz or GHz• In one clock cycle, a CPU

– fetches an instruction from memory,– decodes the instruction, or– executes the instruction

• Pipelining allows overlap of operations to improve performance

• 2-Ghz CPU can execute 2 billion instructions per second

CSE 1301 1A-18/54

Memory or Storage Devices• Memory consists of cells that hold one

bit.• A bit's value can be 0 or 1• A byte is 8 binary digits (bits)

CSE 1301 1A-19/54

From Dell:

CSE 1301 1A-20/54

Memory has width(word size)

Memory hascapacity

CSE 1301 1A-21/54

Memory• Main memory is volatile - stored information is lost

if the electric power is removed• Secondary memory devices are nonvolatile• Main memory and disks are direct access devices -

information can be reached directly• The terms direct access and random access often

are used interchangeably• A magnetic tape is a sequential access device since

its data is arranged in a linear order - you must get by the intervening data in order to access other information

CSE 1301 1A-22/54

Software Categories• Operating System

– Resource manager/coordinator

• Shell– Interface between the OS and the user and

applications

• Applications– What the user sees

CSE 1301 1A-23/54

CSE 1301 1A-24/54

Operating System Software• boots when computer is turned on and runs

continuously• Controls the peripheral devices (disks, keyboard,

mouse, etc.)• Supports multitasking (multiple programs executing

simultaneously)• Allocates memory to each program• Prevents one program from damaging another

program• Example: Microsoft Windows, Linux

CSE 1301 1A-25/54

Application Software• Written to perform specific tasks• Runs "on top of" operating system• Examples: word processor,

spreadsheet, database management system, games, Internet browser, etc.

Client/Server• What is the OS here?• What is the

application?• Where does data

live?• How to we coordinate

the application among many users?

1-26

What is better?

1-27

CSE 1301 1A-28/54

• Analog information is continuous• Digital information is discrete

CSE 1301 1A-29/54

• Sampling induces losses

• Humans can hear 20Hz-20kHz

• 44.1 kHz typical sample rate (CD)

• Sample rate >= double frequency - Nyquist (1924)

CSE 1301 1A-30/54

CSE 1301 1A-31/54

Why do we care?• Computers are dumb• They’re just dumb at a really fast rate

– 2.8gHz computer can perform 2.8 billion operations per second

• Computers only see in binary (0/1)• Anything we see as meaningful is

strings of 0s and 1s

CSE 1301 1A-32/54

Digital Information• Computers store all information digitally:

– numbers– text– graphics and images– video– audio– program instructions

• In some way, all information is digitized - broken down into pieces and represented as numbers

CSE 1301 1A-33/54

Representing Text Digitally• For example, every character is stored as a number,

including spaces, digits, and punctuation

• Corresponding upper and lower case letters are separate characters

H i , H e a t h e r .

72 105 44 32 72 101 97 116 104 101 114 46

CSE 1301 1A-34/54

Binary Numbers• Once information is digitized, it is represented and

stored in memory using the binary number system

• A single binary digit (0 or 1) is called a bit

• Devices that store and move information are cheaper and more reliable if they have to represent only two states

• A single bit can represent two possible states, like a light bulb that is either on (1) or off (0)

• Permutations of bits are used to store values

CSE 1301 1A-35/54

Data Representation • Binary Numbers

– Expressed in base 2 system (two values are 0 and 1)

• Hexadecimal Numbers– Base-16 system used as shorthand for

binary numbers

• Representing Characters with the Character Set

CSE 1301 1A-36/54

Converting & Bases• Binary• Oct• Dec• Hex

CSE 1301 1A-37/54

Binary Equivalents of Decimal Numbers Decimal Binary Equivalent

0 0000

1 0001

2 0010

3 0011

4 0100

5 0101

6 0110

7 01118 1000

CSE 1301 1A-38/54

Powers of 2 Decimal

Decimal

20 1 28 256

21 2 29 512

22 4 210 1024

23 8 211 2048

24 16 212 4096

25 32 213 8192

26 64 214 16384

27 128 215 32768

Notice with each additional bit, it doubles the possible number of values.

CSE 1301 1A-39/54

CSE 1301 1A-40/54

Decimal (base 10) numbers• A decimal number can be represented as the

sum of powers of 10 (the base) with coefficients in the base 10 alphabet (0 - 9)

For example:2485 = 2000 + 400 + 80 + 5

2485 = 2 * 1000 + 4 * 100 + 8 * 10 + 5 * 1

2485 = 2 * 103 + 4 * 102 + 8 * 101 + 5 * 100

CSE 1301 1A-41/54

Converting from Binary to Decimal101101 = ?

CSE 1301 1A-42/54

Converting From Decimal to Binary• Just as a decimal number can be

represented as a sum of powers of 10 (the base) with coefficients in the base 10 alphabet (0 to 9),

• A decimal number also can be represented as the sum of powers of 2 (the base of the binary system) with coefficients in the base 2 alphabet (0 and 1)

• So we need an algorithm to do that

CSE 1301 1A-43/54

1. Find the largest power of 2 that is smaller than or equal to the decimal number

2. Subtract that number from the decimal number

3. Insert 1 in binary number for position equivalent to that power of 2

4. Repeat 1 - 3, until you reach 0

Converting From Decimal to Binary

CSE 1301 1A-44/54

Example: convert 359 to binary1. Largest power of 2 that is smaller than

359 is 256 (28)

2. 359 - 256 = 103

so 359 = 28*1 + 103

3. Largest power of 2 that is smaller than 103 is 64 (26)

4. 103 - 64 = 39

so 359 = 28*1 + 26*1 + 39

(continued on next slide)

CSE 1301 1A-45/54

Example: convert 359 to binary5. Largest power of 2 that is smaller than

39 is 32 (25)

6. 39 - 32 = 7

so 359 = 28*1 + 26*1 + 25*1 + 7

7. Largest power of 2 that is smaller than 7 is 4 (22)

8. 7 - 4 = 3

so 359 = 28*1 + 26*1 + 25*1 + 22*1 + 3

(continued on next slide)

CSE 1301 1A-46/54

Example: convert 359 to binary

9. Largest power of 2 that is smaller than 3 is 2 (21)

10.3 - 2 = 1

so 359 = 28*1 + 26*1 + 25*1 + 22*1 + 21*1 + 1

11. Largest power of 2 that is smaller than or equal to 1 is 1 (20)

12.1 - 1 = 0, so we are finished

CSE 1301 1A-47/54

Our resultsFinally, insert missing powers of 2 with coefficient 0.

Thus, 359 =

28*1 + 27*0 + 26*1 + 25*1 + 24*0 + 23*0 + 22*1 + 21*1 + 20*1

Removing powers of 2, we get:

1 0 1 1 0 0 1 1 1

Or

1 0110 0111

CSE 1301 1A-48/54

Hexadecimal Numbers• Base-16 number system• Uses digits 0 - 9 and letters A - F• One hexadecimal digit can express

values from 0 to 15 – For example: C represents 12

• Thus, one hexadecimal digit can represent 4 bits

CSE 1301 1A-49/54

Hexadecimal - Binary Equivalents

Hex Binary Hex Binary

0 0000 8 1000

1 0001 9 1001

2 0010 A 1010

3 0011 B 1011

4 0100 C 1100

5 0101 D 1101

6 0110 E 1110

7 0111 F 1111

CSE 1301 1A-50/54

ExamplesBinary number: 0001 1010 1111 1001

Hex equivalent: 1 A F 9

Binary number: 1011 0011 1011 1110

Hex equivalent: B 3 B E

CSE 1301 1A-51/54

Practice with Number Systems1002 = ?16

371616 = ?2

1101001112 = ?10

3A1B16 = ?2

CSE 1301 1A-52/54

Practice with Number Systems1002 = 416

371616 = 0011 0111 0001 11002

1101001112 = 42310

3A1B16 = 0011 1010 0001 10112

CSE 1301 1A-53/54

The Unicode Character Set• Each character stored as 16-bits• Maximum number of characters that can be

represented: 65,536 (216) (w_char )• ASCII character set (used by many

programming languages) stores each character as 7 bits (maximum number of characters is 128).

• For compatibility, first 128 characters of Unicode set represent the ASCII characters

CSE 1301 1A-54/54

ASCII American Standard Code for Information InterchangeChar Dec Oct Hex | Char Dec Oct Hex | Char Dec Oct Hex | Char Dec Oct Hex-------------------------------------------------------------------------------------(nul) 0 0000 0x00 | (sp) 32 0040 0x20 | @ 64 0100 0x40 | ` 96 0140 0x60(soh) 1 0001 0x01 | ! 33 0041 0x21 | A 65 0101 0x41 | a 97 0141 0x61(stx) 2 0002 0x02 | " 34 0042 0x22 | B 66 0102 0x42 | b 98 0142 0x62(etx) 3 0003 0x03 | # 35 0043 0x23 | C 67 0103 0x43 | c 99 0143 0x63(eot) 4 0004 0x04 | $ 36 0044 0x24 | D 68 0104 0x44 | d 100 0144 0x64(enq) 5 0005 0x05 | % 37 0045 0x25 | E 69 0105 0x45 | e 101 0145 0x65(ack) 6 0006 0x06 | & 38 0046 0x26 | F 70 0106 0x46 | f 102 0146 0x66(bel) 7 0007 0x07 | ' 39 0047 0x27 | G 71 0107 0x47 | g 103 0147 0x67(bs) 8 0010 0x08 | ( 40 0050 0x28 | H 72 0110 0x48 | h 104 0150 0x68(ht) 9 0011 0x09 | ) 41 0051 0x29 | I 73 0111 0x49 | i 105 0151 0x69(nl) 10 0012 0x0a | * 42 0052 0x2a | J 74 0112 0x4a | j 106 0152 0x6a(vt) 11 0013 0x0b | + 43 0053 0x2b | K 75 0113 0x4b | k 107 0153 0x6b(np) 12 0014 0x0c | , 44 0054 0x2c | L 76 0114 0x4c | l 108 0154 0x6c(cr) 13 0015 0x0d | - 45 0055 0x2d | M 77 0115 0x4d | m 109 0155 0x6d(so) 14 0016 0x0e | . 46 0056 0x2e | N 78 0116 0x4e | n 110 0156 0x6e(si) 15 0017 0x0f | / 47 0057 0x2f | O 79 0117 0x4f | o 111 0157 0x6f(dle) 16 0020 0x10 | 0 48 0060 0x30 | P 80 0120 0x50 | p 112 0160 0x70(dc1) 17 0021 0x11 | 1 49 0061 0x31 | Q 81 0121 0x51 | q 113 0161 0x71(dc2) 18 0022 0x12 | 2 50 0062 0x32 | R 82 0122 0x52 | r 114 0162 0x72(dc3) 19 0023 0x13 | 3 51 0063 0x33 | S 83 0123 0x53 | s 115 0163 0x73(dc4) 20 0024 0x14 | 4 52 0064 0x34 | T 84 0124 0x54 | t 116 0164 0x74(nak) 21 0025 0x15 | 5 53 0065 0x35 | U 85 0125 0x55 | u 117 0165 0x75

From: http://web.cs.mun.ca/~michael/c/ascii-table.html

top related