280 likes | 391 Vues
Programming in C. Introduction to Computers. Programming in C. sophir@techst02.technion.ac.il. Central Processing Unit. Basic Model of Computers. Control Processing Unit (CPU). Executes Programs. Program = A Sequence of Machine Instructions.
E N D
Introduction to Computers Programming in C sophir@techst02.technion.ac.il
Central Processing Unit Basic Model of Computers • Control Processing Unit (CPU) • Executes Programs • Program = • A Sequence of Machine • Instructions
Central Processing Unit Control Unit Basic Model of Computers • Control Unit (CU) • Determines which instruction • must be executed next. • Retrieves the needed data from • the memory • Coordinates the execution • of the instruction
Central Processing Unit Control Unit Arithmetic Logic Unit Basic Model of Computers • Arithmetic Logic Unit (ALU) • Performs Simple operations: Add, Subtract, Multiply, ...
Central Processing Unit Registers Basic Model of Computers • Registers Control Unit • Fast memory used to hold • the intermediate result of • operations Arithmetic Logic Unit
Central Processing Unit Memory Basic Model of Computers • Memory (RAM) Control Unit • holds data and • instructions Arithmetic Logic Unit • Random Access Registers • volatile
Central Processing Unit Memory Disk Basic Model of Computers • Disk Control Unit • holds data and • programs Arithmetic Logic Unit • nonvolatile Registers
Central Processing Unit Memory Disk Display Printer Basic Model of Computers • And other peripherals Control Unit Arithmetic Logic Unit Registers . . .
Central Processing Unit Memory Disk Display Printer Basic Model of Computers • Bus • Data passage way • between parts of • the computer Control Unit Arithmetic Logic Unit Registers . . .
CPU • Repeatedly does the following: • Gets the next instruction from the memory • Gets the data required to execute the instruction from the memory • Performs the instruction • Stores the result in the memory
Machine Instructions • Add the content of memory location 6 to the content of memory location 7 and store the result in memory location 8. Load 6 Add 7 Store 8 End
Memory Machine Instructions CPU 1 Load 6 2 Add 7 3 Store 8 End 4 5 6 1 7 5 8
Memory Machine Instructions CPU Load 6 1 Load 6 2 Add 7 3 Store 8 End 4 5 6 1 7 5 8
Memory Machine Instructions CPU Load 6 1 Load 6 2 Add 7 1 3 Store 8 End 4 5 6 1 7 5 8
Memory Machine Instructions CPU Add 7 1 Load 6 2 Add 7 1 3 Store 8 End 4 5 6 1 7 5 8
Memory Machine Instructions CPU Add 7 1 Load 6 2 Add 7 1 5 3 Store 8 End 4 5 6 1 7 5 8
Memory Machine Instructions CPU Add 7 1 Load 6 2 Add 7 + 1 5 3 Store 8 End 4 5 6 1 7 5 8
Memory Machine Instructions CPU Add 7 1 Load 6 2 Add 7 + 1 5 3 Store 8 End 4 5 6 1 7 5 6 8
Memory Machine Instructions CPU Store 8 1 Load 6 2 Add 7 + 1 5 3 Store 8 End 4 5 6 1 7 5 6 8
Memory Machine Instructions CPU Store 8 1 Load 6 2 Add 7 + 1 5 3 Store 8 End 4 5 6 1 7 5 6 6 8
Memory Memory • A Sequence of Memory Cells (Words) Word
Word Word • A Sequence of 4 Bytes Byte 0 Byte 1 Byte 2 Byte 3
Byte • A Sequence of 8 Bits Word Byte 0 Byte 1 Byte 2 Byte 3
1 0 0 1 0 1 1 0 . . . 0 1 1 1 Bit • A switch capable of being in one of two states: • On state: Represents 1 • Off state: Represents 0 Word 0 1 2 3 4 5 6 7 28 29 30 31
Decimal Numbers • Each digit is: • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 • 453 => 3x100 + 5x101 + 4x102
Binary Numbers • Each digit is: • 0, 1 • 101 => 1x20 + 0x21 + 1x22 => 5
Ex - Decimal Numbers • Each digit is: • 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,A ,B ,C ,D ,E ,F • 1E3 => 3x160 + 14x161 + 1x162 => 343