29
Chapter 2: Chapter 2: Data Manipulation Data Manipulation

Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Embed Size (px)

Citation preview

Page 1: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Chapter 2:Chapter 2:Data ManipulationData Manipulation

Page 2: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 3: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 4: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Inside the System UnitInside the System Unit

Page 5: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3
Page 6: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Figure 2.1Figure 2.1 CPU and main CPU and main memory connected via a memory connected via a

busbus

Page 7: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 8: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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.

Page 9: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 10: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 11: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 12: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 13: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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).

Page 14: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Control InstructionsControl Instructions

JumpJump HaltHalt

Page 15: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 16: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 17: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Figure 2.2Figure 2.2 Adding values Adding values stored in memorystored in memory

Page 18: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Figure 2.4Figure 2.4 The architecture The architecture of the machine described in of the machine described in

Appendix CAppendix C

Page 19: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 20: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 21: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 22: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Figure 2.6Figure 2.6 Decoding the Decoding the instruction 35A7instruction 35A7

Page 23: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Figure 2.7Figure 2.7 An encoded An encoded version of the version of the

instructions in Figure 2.2instructions in Figure 2.2

Page 24: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 25: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Figure 2.8Figure 2.8 The machine The machine cyclecycle

Page 26: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Figure 2.9Figure 2.9 Decoding the Decoding the instruction B258instruction B258

Page 27: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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

Page 28: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

Figure 2.11Figure 2.11 Performing Performing the fetch step of the the fetch step of the

machine cyclemachine cycle

Page 29: Chapter 2: Data Manipulation. 2.1 Computer Architecture 2.1 Computer Architecture 2.2 Machine Language 2.2 Machine Language 2.3 Program Execution 2.3

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)