28
ntroduction to Computers Bina © 1998 Liran & Ofir Programming in C

Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Embed Size (px)

Citation preview

Page 1: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Programming in

C

Page 2: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Introduction to ComputersIntroduction to ComputersIntroduction to ComputersIntroduction to Computers

Programming in Programming in

CC

[email protected]

Page 3: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Central Processing Unit

Basic Model of ComputersBasic Model of ComputersBasic Model of ComputersBasic Model of Computers

Control Processing Unit (CPU)Control Processing Unit (CPU)

Executes ProgramsExecutes Programs

Program = Program = A Sequence of MachineA Sequence of Machine InstructionsInstructions

Page 4: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Central Processing Unit

Basic Model of ComputersBasic Model of ComputersBasic Model of ComputersBasic Model of Computers

Control Unit Control Unit (CU)Control Unit (CU)

Determines which instructionDetermines which instruction must be executed next.must be executed next.

Retrieves the needed data fromRetrieves the needed data from the memorythe memory

Coordinates the execution Coordinates the execution of the instructionof the instruction

Page 5: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Central Processing Unit

Control Unit

Basic Model of ComputersBasic Model of ComputersBasic Model of ComputersBasic Model of Computers

ArithmeticLogic Unit

Arithmetic Logic Unit (ALU)Arithmetic Logic Unit (ALU)

Performs Simple operations:Performs Simple operations:

Add,Add,

Subtract,Subtract,

Multiply,Multiply,

......

Page 6: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Central Processing Unit

Basic Model of ComputersBasic Model of ComputersBasic Model of ComputersBasic Model of Computers

Control Unit

ArithmeticLogic Unit

Registers

RegistersRegisters

Fast memory used to holdFast memory used to hold the intermediate result ofthe intermediate result of operationsoperations

Page 7: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Central Processing Unit

Basic Model of ComputersBasic Model of ComputersBasic Model of ComputersBasic Model of Computers

Memory

Control Unit

ArithmeticLogic Unit

Registers

Memory (RAM)Memory (RAM) holds data andholds data and instructionsinstructions

Random AccessRandom Access

volatilevolatile

Page 8: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Central Processing Unit

Memory

Basic Model of ComputersBasic Model of ComputersBasic Model of ComputersBasic Model of Computers

Disk

Control Unit

ArithmeticLogic Unit

Registers

DiskDisk holds data andholds data and programsprograms

nonvolatilenonvolatile

Page 9: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Central Processing Unit

Memory

Basic Model of ComputersBasic Model of ComputersBasic Model of ComputersBasic Model of Computers

Disk

Control Unit

ArithmeticLogic Unit

Registers

And other peripheralsAnd other peripherals

Display

Printer

. . .

Page 10: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Central Processing Unit

Memory

Basic Model of ComputersBasic Model of ComputersBasic Model of ComputersBasic Model of Computers BusBus

Data passage wayData passage way between parts ofbetween parts of the computer the computer

DisplayDisk

Control Unit

ArithmeticLogic Unit

RegistersPrinter

. . .

Page 11: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

CPUCPUCPUCPU

Repeatedly does the following:Repeatedly does the following:

Gets the next instruction from the memoryGets the next instruction from the memory

Gets the data required to execute the instruction Gets the data required to execute the instruction

from the memoryfrom the memory

Performs the instructionPerforms the instruction

Stores the result in the memoryStores the result in the memory

Page 12: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

Add the content of memory location 6 to Add the content of memory location 6 to the content of memory location 7 and store the content of memory location 7 and store the result in memory location 8.the result in memory location 8.

Load 6Load 6

Add 7Add 7

Store 8Store 8

EndEnd

Page 13: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

CPU

Memory

1

67

32

8

45

51

Load 6Add 7Store 8End

Page 14: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

CPU

Memory

1

67

32

8

45

51

Load 6 Load 6Add 7Store 8End

Page 15: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

CPU

Memory

1

67

32

8

45

51

Load 6 Load 6Add 7Store 8End

1

Page 16: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

CPU

Memory

1

67

32

8

45

51

Load 6Add 7Store 8End

1

Add 7

Page 17: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

CPU

Memory

1

67

32

8

45

51

Load 6Add 7Store 8End

1 5

Add 7

Page 18: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

CPU

Memory

+

1

67

32

8

45

51

Load 6Add 7Store 8End

1 5

Add 7

Page 19: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

CPU

Memory

+

1

67

32

8

45

51

Add 7 Load 6Add 7Store 8End

1 5

6

Page 20: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

CPU

Memory

+

1

67

32

8

45

51

Load 6Add 7Store 8End

1 5

6

Store 8

Page 21: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Machine InstructionsMachine InstructionsMachine InstructionsMachine Instructions

CPU

Memory

+

1

67

32

8

45

51

6

Store 8 Load 6Add 7Store 8End

1 5

6

Page 22: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

MemoryMemoryMemoryMemory

A Sequence of Memory CellsA Sequence of Memory Cells

(Words)(Words)Memory

Word

Page 23: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

WordWordWordWord

A Sequence of 4 A Sequence of 4 BytesBytes

Word

Byte 0 Byte 3Byte 2Byte 1

Page 24: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Byte 0 Byte 3Byte 2Byte 1

ByteByteByteByte

A Sequence of 8 A Sequence of 8 BitsBits

Word

Page 25: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

BitBitBitBit

A switch capable of being in one of two A switch capable of being in one of two states:states:

0 1 2 3 4 5 6 7 28 2930 31

Word

On state: Represents 1On state: Represents 1

Off state: Represents 0Off state: Represents 0

0 0 . . .1 1 1 10 0 0 1 1 1

Page 26: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Decimal NumbersDecimal NumbersDecimal NumbersDecimal Numbers

Each digit is:Each digit is:

0, 1, 2, 3, 4, 5, 6, 7, 8, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9

453 => 3x10453 => 3x1000 + 5x10 + 5x1011 + 4x10 + 4x1022

Page 27: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Binary NumbersBinary NumbersBinary NumbersBinary Numbers

Each digit is:Each digit is:

0, 10, 1

101 => 1x2101 => 1x200 + 0x2 + 0x211 + 1x2 + 1x222 => 5 => 5

Page 28: Introduction to ComputersS1.1.1 Bina © 1998 Liran & Ofir Programming in C

Introduction to Computers Bina © 1998 Liran & Ofir

Ex - Decimal NumbersEx - Decimal NumbersEx - Decimal NumbersEx - Decimal Numbers

Each digit is:Each digit is:

0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,A ,B ,C ,D ,E ,F0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,A ,B ,C ,D ,E ,F 1E3 => 3x161E3 => 3x1600 + 14x16 + 14x1611 + 1x16 + 1x1622 => 343 => 343