Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and...

30
Basics Hardware and Number Representation S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Transcript of Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and...

Page 1: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Basics

Hardware andNumber Representation

Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Page 2: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Computer Organization

CPU - central processing unit

Memory

Input devices

Output devices

CPU - central processing unit Where decisions are made, computations are

performed, and input/output requests are delegatedMemory

Stores information being processed by the CPU

Input devices Allows people to supply information to computers

Output devices Allows people to receive information from computers

Page 3: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Computer Organization

Memory

CPU

InputDevices

OutputDevices

bus

Page 4: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

CPUCPU: Brains of the computer

Arithmetic calculations are performed using the Arithmetic/Logical Unit or ALU

Control unit decodes and executes instructionsArithmetic operations are performed using binary number systemCPU executes instructions which are stored in memoryProgram = sequence of instructions

E.g:1. Cut potatoes2. Boil for 10 minutes3. Fry with salt and pepper

Page 5: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

“Toy” InstructionsInstruction formats:

operation.location.location operation.location.value operation value

E.g. operation codes: 1 = Set, 4 = read from keyboard 5 = add, 9 = print to screen

Location

Value Meaning

1 1.100.12 Set M100 12

2 4.101 Read into M101

3 5.101.100 M101 = M100+M101

4 9.101 Print M101

Page 6: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Program Execution

Fetch the instruction towhich the PC points

Increment the Program Counter

Execute the fetchedinstruction

Location

Value Meaning

1 1.100.12 Set M100 12

2 4.101 Read into M101

3 5.101.100 M101 = M100+M101

4 9.101 Print M101

Page 7: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Control Unit

The fetch/execute cycle is the steps the CPU takes to execute an instructionPerforming the action specified by an instruction is known as executing the instructionThe program counter (PC) holds the memory address of the next instruction

Fetch the instruction towhich the PC points

Increment the PC

Execute the fetchedinstruction

Page 8: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Input and Output Devices

Accessories that allow computer to perform specific tasks

Receive information for processing Return the results of processing Store information

Accessories that allow computer to perform specific tasks

Receive information for processing Return the results of processing Store information

Common input and output devices Speakers Mouse Scanner Printer Joystick CD-ROM Keyboard Microphone DVD

Accessories that allow computer to perform specific tasks

Receive information for processing Return the results of processing Store information

Common input and output devices Speakers Mouse Scanner Printer Joystick CD-ROM Keyboard Microphone DVD

Some devices are capable of both input and output Floppy drive Hard drive Magnetic tape

units

Page 9: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Examples Linux, Windows®, UNIX®, Mac OS X®

Controls and manages the computing resources

Important services that an operating system provides File system

Directories, folders, files Commands that allow for manipulation of the file system

Sort, delete, copy Ability to perform input and output on a variety of

devices Management of the running systems Time sharing of processes, and protection from each

other

Operating System

Page 10: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Binary Number Representation

Early mechanical computers used decimal notationBinary is much easier to implement in electronic computers

Switch is On or Off E.g. 0 Volts = 0 3 Volts = 1

Voltages in-between should not occur (except very close to 0 or 3 volts)

Storage elements (e.g. “flip-flop” circuits) can be in state 0 or 1

state can be changed by signal

Page 11: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

The individual digits of a binary number are referred to as bits Each bit represents a power of two Most-significant and least-significant bits

01011 = 0 • 24 + 1 • 23 + 0 • 22 + 1 • 21 + 1 • 20 = 11

00010 = 0 • 24 + 0 • 23 + 0 • 22 + 1 • 21 + 0 • 20 = 2

Binary Arithmetic

00010 + 01011 01101

Binaryaddition

2+ 11 13

Equivalentdecimaladdition

4 3 2 1 0 (Power of 2)

Page 12: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Logic Circuits

Basic logic circuits: AND, OR, NOT

AND OR NOT

0 1

0 0 0

1 0 1B

A 0 1

0 0 1

1 1 1B

A A

0 1

1 0

Page 13: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Binary Addition1. S0 = (A0 or B0) and not (A0 and B0)2. C1 = A0 and B03. S1 = (C1 and A1 and B1)

or (C1 and (not A1) and (not B1)) or ((not C1) and A1 and (not B1)) or ((not C1) and (not A1) and B1)

4. C2 = (C1 and A1) or (C1 and B1) or (A1 and B1)

5. Ci, Si similarly defined for other i

C carry

00010 A + 01011 B 01101 S sum

4 3 2 1 0

AND

OR

NOTAND

A0

B0S0

Page 14: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Binary Arithmetic

5×11 55

Equivalent decimal multiplication

0101 × 1011 0101 0101 0000 0101 0110111

Binary multiplication

• Implemented in hardware using multiple shift-left

and add steps

Shift A left to multiply by B1 (= 21)

AB

Since B2 = 0

• Manual verification: 32 + 16 + 4 + 2 + 1 = 55

Page 15: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Negative Numbers: Two’s Complement

Representation for signed binary numbers

Leading bit is a sign bit Binary number with leading 0 is positive Binary number with leading 1 is negative

Magnitude of positive numbers is just the binary representation

Magnitude of negative numbers is found by Complement the bits Replace all the 1's with 0's, and all the 0's with 1's Add one to the complemented number

The carry in the most significant bit position is thrown away when performing arithmeticWhy this complexity? To allow addition to work the same way for +ve and –ve numbers

Page 16: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Two’s Complement

Performing two's complement on the decimal 7 to get -7 Using a five-bit representation

7 = 00111 Convert to binary

11000 Complement the bits

11000 Add 1 to the complement + 00001 11001 Result is -7 in two's complement

Page 17: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Two's Complement Arithmetic

Computing 8 - 7 using a two's complement representation with five-bit numbers

8 - 7 = 8 + (-7) = 1

01000 Two's complement representation of 8

11001 Two's complement representation of -7

01000 Add 8 and -7 + 11001 100001

00001 Is the five-bit result

Throw away the high-order

carry as we are using a five bit representation

Page 18: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Overflow in 2’s Complement

With 5 bits, what is 15 + 15? 01111 + 01111 = 11110

which represents -2 (Flip bits to get 00001, add 1 to get 00010)

What happened? Overflow With 5 bits, maximum unsigned number is

1+2+4+8+16=31, but maximum 2’s complement number is 15 (min is -16)

Page 19: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Real Numbers

“Floating point” representation E.g. 3.1415 = .31415 x 101

3141.5 = .31415 x 104

0.0031415 = .31415 x 10-2

-31.415 = -.31415 x 102

Note that .31415 = 3 x 10-1 + 1 x 10-2 + 4 x 10-3 + 1 x 10-4+ 5 x 10-5

2-part number representation: Mantissa: fractional part (in binary), with signExponent: power of 2, with signIn C/C++ notation: 0.31415E1 = 3.1415

-0.31415E-1 = - .031415

Page 20: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Binary Floating Point Representation

In binary: .1011 = 1 x 2-1 + 0 x 2-2 + 1 x 2-3 + 1 x 2-4

101.1 = .1011 x 23

2-part number representation: Mantissa: fractional part (in binary, with sign)Exponent: power of 2 (in binary, with sign)Total number of bits divided into sign, mantissa, and

exponent E.g. 32 bits: 21 bit mantissa (1 sign bit + 20 bits),

11 bit exponent (1 sign bit + 10 bits) Gives 10 bits for exponent and exponent from 2-10 to 210

Numbers up to 2 power 210

Exponent Mantissa

Page 21: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Floating Point StandardsIEEE 754 Floating point standard

Special codes for +/- infinity, not-a-number (NaN) +0 and -0

32 bit (Single precision) sign bit Exponent uses 8-bit “biased” representation (store

exponent+127) Exponent range from -126 to + 127

Mantissa (fraction) is 23 bit 64 bit (Double precision) for computations that require

greater precision sign bit 11 bit exponent (store exponent + 1023) and 52 bit mantissa

Page 22: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Arithmetic on Real Numbers

Arithmetic on real numbers more complicatedMost ALU (arithmetic and logic units) do only integer arithmeticReal (floating point) arithmetic is done

in software on some low-end processors in a floating-point unit on most modern processors

Most processors today support single and double precision floating point arithmetic

Page 23: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Computer Organization

Memory

CPU

InputDevices

OutputDevices

CPU Memory

Address+Control Bus

Data Bus

Page 24: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Memory

Units of memory 1 bit: 0 or 1 Byte = 8 bits Word: depends on CPU, typically 32 bits (4 bytes) 1 Kilobyte(KB) = 210 = 1024 bytes 1 Megabyte (MB) = 220 = 1024 Kilobytes 1 Gigabyte (GB) = 230 = 1024 Megabytes

Main memory (Random Access Memory, or RAM) fast, but volatile (i.e. contents lost on power off) access time ~ 100 nano sec (nano = 10-9)

Random access: to any specified part of memory typical capacity today: 512 MB to a few GB

Page 25: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Magnetic Disks

Magnetic disk Data stored magnetically on disk platter typical capacity today: 80 GB to 400 GB Per-byte cost << main memory data retained even if power is off To read from a specific disk location

Read/write head (disk arm) moves to correct distance from center

Disk rotates till specific location is under the head. Random access is slow

5 milliseconds to read a randomly specified piece of data Sequential access (once head has reached location) is fast

40 MB/sec to 80 MB/sec today

Page 26: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Other Forms of Memory

Optical disk (CD, DVD)Flash memory

Memory is preserved even on power off In between main memory and disk in terms of

cost per byte memory size (few GB typical today) speed of access (close to main memory)

Widely used, e.g. Mobile phones Digital cameras USB keys (Pen drive) for transferring data

Page 27: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

CPU

Processors have a clock that “ticks” (1 tick = 1cycle) Nominally one instruction per clock cycle

Usually much less because memory is slower Clock speeds today: a few Gigahertz

Can have multiple processors executing different programs in parallel

Were very expensive earlier, widely available today E.g. Pentium Core Duo: 2 processors

Page 28: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Communication Technologies

Serial port / Parallel port: old technologies E.g. old mice, keyboards, printers

USB (Universal Serial Bus): connection between computer and peripherals

E.g. computer to mobile phoneIDE/SATA/.. : connection technologies to connect hard disks to computers

Don’t worry about what the names mean!Ethernet: connection to computer networks

100 Mb/sec to 1Gb/sec (Mb = Megabit, Gb = Gigabit)Optical fiber: backbone of computer networks

Multiple 1 to 10 Gb/sec channels per fiber

Page 29: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Communication (Cont.)

Wireless Communication Bluetooth: standard for short distances of a few metres

slow (1 Mb/sec) WiFi: standard for communication within a few 10s to 100

metres High speed (10 to 50 Mb/sec)

GSM/CDMA: mobile phone protocols several kilometres, but very slow (and expensive) for

data typical 14 Kb/sec

Faster long distance protocols under development (WiMax)

Page 30: Basics Hardware and Number Representation Adapted by S. Sudarshan from slides provided by: JPC and JWD © 2002 McGraw-Hill, Inc.

Monitor

Pixel: single dot on screenScreen: 2-D array of pixelsResolution: number of pixels along each axis

E.g. 1280x1024, 1024 x 768, 800x600 Widescreen (e.g.): 1366x768, 1920x1200

Bits per pixel 3 colors (Red, Green, Blue) per pixel 8 bits/color typical

= 24 bits, or 3 Bytes per pixel 1024x1024 screen: 3 MB memory for screen (Graphics

memory)