Post on 05-Jan-2016
description
transcript
Chapter 2:Chapter 2:Data ManipulationData Manipulation
Chapter 2: Data Chapter 2: Data ManipulationManipulation
2.1 Computer Architecture2.1 Computer Architecture 2.2 Machine Language2.2 Machine Language 2.3 Program Execution2.3 Program Execution
Computer ArchitectureComputer Architecture Central Processing Unit (CPU) or processorCentral Processing Unit (CPU) or processor
Arithmetic/Logic unit versus Control unitArithmetic/Logic unit versus Control unit Registers : temporary storage units within the Registers : temporary storage units within the
CPU that hold data being processed and are very CPU that hold data being processed and are very easily accessible by CPU. Two types of Registerseasily accessible by CPU. Two types of Registers
General purpose : Can be used for any taskGeneral purpose : Can be used for any task Special purpose : Used for special task e.g Special purpose : Used for special task e.g
Program Counter ( PC) and Instruction Program Counter ( PC) and Instruction Register (IR)Register (IR)
BusBus MotherboardMotherboard
Inside the System UnitInside the System Unit
Figure 2.1Figure 2.1 CPU and main CPU and main memory connected via a memory connected via a
busbus
Bus and its typesBus and its types
A bus connects parts of the CPU to one A bus connects parts of the CPU to one another. It also links the CPU to the another. It also links the CPU to the various components of the system various components of the system board.board.
There are three types of buses:There are three types of buses: Data BusData Bus Address BusAddress Bus Control BusControl Bus
Von Neumann Stored Von Neumann Stored Program ConceptProgram Concept
A program can be encoded as bit A program can be encoded as bit patterns and stored in main memory. patterns and stored in main memory. From there, the CPU can then From there, the CPU can then extract the instructions and execute extract the instructions and execute them. In turn, the program to be them. In turn, the program to be executed can be altered easily.executed can be altered easily.
Terminology Terminology
Machine instruction:Machine instruction: An An instruction (or command) encoded instruction (or command) encoded as a bit pattern recognizable by the as a bit pattern recognizable by the CPUCPU
Machine language:Machine language: The set of all The set of all instructions recognized by a instructions recognized by a machinemachine
Machine Instruction Machine Instruction TypesTypes
Data Transfer: copy data from one Data Transfer: copy data from one location to anotherlocation to another
Arithmetic/Logic: use existing bit Arithmetic/Logic: use existing bit patterns to compute a new bit patterns to compute a new bit patternspatterns
Control: direct the execution of the Control: direct the execution of the programprogram
Data Transfer Data Transfer InstructionsInstructions
Load : To fetch data from Main Load : To fetch data from Main MemoryMemory
Store : To save data into Main Store : To save data into Main MemoryMemory
Move: To transfer data from Move: To transfer data from register to registerregister to register
Arithmetic / Logical Arithmetic / Logical InstructionsInstructions
Add / Sub / Mult / Div / ModAdd / Sub / Mult / Div / Mod
And / OR / XOR / NOT /SHIFT And / OR / XOR / NOT /SHIFT /ROTATE/ROTATE
Arithmetic/Logic Arithmetic/Logic OperationsOperations
Logic: AND, OR, XORLogic: AND, OR, XOR MaskingMasking
Rotate and Shift: circular shift, Rotate and Shift: circular shift, logical shift, arithmetic shiftlogical shift, arithmetic shift
Arithmetic: add, subtract, multiply, Arithmetic: add, subtract, multiply, dividedivide Precise action depends on how the Precise action depends on how the
values are encoded (two’s complement values are encoded (two’s complement versus floating-point).versus floating-point).
Control InstructionsControl Instructions
JumpJump HaltHalt
What is a High Level What is a High Level Language and Machine Language and Machine
LanguageLanguage A High Level Language is easily A High Level Language is easily
understood by human beingsunderstood by human beings A Machine Language Instruction is A Machine Language Instruction is
in Binary format easily understood in Binary format easily understood by the Machine / Computerby the Machine / Computer
Difference ?? Difference ?? One High Level Language One High Level Language
Instruction gets translated into Instruction gets translated into Many Machine Level Instructions Many Machine Level Instructions thus taking more time to executethus taking more time to execute
ExampleExample
If I write in High Level LanguageIf I write in High Level Language a:= b+c a:= b+c It gets translated into 4 machine It gets translated into 4 machine
level instructions:level instructions:
1.1. Fetch bFetch b
2.2. Fetch cFetch c
3.3. Add b and cAdd b and c
4.4. Store their result in aStore their result in a
Figure 2.2Figure 2.2 Adding values Adding values stored in memorystored in memory
Figure 2.4Figure 2.4 The architecture The architecture of the machine described in of the machine described in
Appendix CAppendix C
Difference Between PC Difference Between PC and IRand IR
Program counter (PC) :Program counter (PC) : It contains the address of the next It contains the address of the next
instruction to be executedinstruction to be executed
Instruction Register:Instruction Register: It contains the Instruction that is It contains the Instruction that is
currently being executed by the CPUcurrently being executed by the CPU
Parts of a Machine Parts of a Machine InstructionInstruction
Op-code:Op-code: Specifies which operation Specifies which operation to executeto execute
Operand:Operand: Gives more detailed Gives more detailed information about the operationinformation about the operation Interpretation of operand varies Interpretation of operand varies
depending on op-codedepending on op-code
Figure 2.5Figure 2.5 The The composition of an composition of an instruction for the instruction for the
machine in Appendix Cmachine in Appendix C
Figure 2.6Figure 2.6 Decoding the Decoding the instruction 35A7instruction 35A7
Figure 2.7Figure 2.7 An encoded An encoded version of the version of the
instructions in Figure 2.2instructions in Figure 2.2
Program ExecutionProgram Execution
Controlled by two special-purpose Controlled by two special-purpose registersregisters Program counter: address of next Program counter: address of next
instructioninstruction Instruction register: current instructionInstruction register: current instruction
Machine CycleMachine Cycle FetchFetch DecodeDecode ExecuteExecute
Figure 2.8Figure 2.8 The machine The machine cyclecycle
Figure 2.9Figure 2.9 Decoding the Decoding the instruction B258instruction B258
Figure 2.10Figure 2.10 The program The program from Figure 2.7 stored in from Figure 2.7 stored in main memory ready for main memory ready for
executionexecution
Figure 2.11Figure 2.11 Performing Performing the fetch step of the the fetch step of the
machine cyclemachine cycle
Figure 2.11Figure 2.11 Performing Performing the fetch step of the the fetch step of the
machine cycle (cont’d)machine cycle (cont’d)