chapter 2 data manipulation - james madison university · chapter 2 data manipulation dr. farzana...

48
Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor Department of Computer Science James Madison University 1 Some sldes are adapted from Pearson Education

Upload: duongminh

Post on 17-Apr-2018

228 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Chapter 2Data Manipulation

Dr. Farzana Rahman

Assistant Professor

Department of Computer Science

James Madison University

1Some sldes are adapted from Pearson

Education

Page 2: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

What the chapter is about?

• 2.1 Computer Architecture

• 2.2 Machine Language

• 2.3 Program Execution

• 2.4 Arithmetic/Logic Instructions

• 2.5 Communicating with Other Devices

2Some sldes are adapted from Pearson

Education

Page 3: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Big ideas

• How computer manipulates data

• What is the basic architecture of computer

• How computer is programmed by means of encoded instructions, i.e. machine language

3Some sldes are adapted from Pearson

Education

Page 4: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Computer Architecture

• Central Processing Unit (CPU) or processor

• Bus

• Motherboard

• RAM

• Peripheral devices

4Some sldes are adapted from Pearson

Education

Page 5: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Computer Architecture

Bus

CPU

RAM

Keyboard

HardDisk

Display

CD-ROM

5Some sldes are adapted from Pearson

Education

Page 6: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The Bus

Bus

• What is a bus?

• It is a simplified way for many devices to communicateto each other.

• Looks like a “highway” for information.

• Actually, more like a “basket” that they all share.

CPU RAM Display

6Some sldes are adapted from Pearson

Education

Page 7: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The Bus

Bus

CPU RAM Display

7Some sldes are adapted from Pearson

Education

Page 8: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The Bus

Bus

• Suppose CPU needs to check to see if the user typedanything.

CPU Keyboard Display

8Some sldes are adapted from Pearson

Education

Page 9: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The Bus

Bus

• CPU puts “Keyboard, did the user type anything?” (represented in some way) on the Bus.

CPU Keyboard Display

“Keyboard, did the user type anything?”

9Some sldes are adapted from Pearson

Education

Page 10: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The Bus

Bus

• Each device (except CPU) is a State Machine that constantly checks to see what’s on the Bus.

CPU Keyboard Display

“Keyboard, did the user type anything?”

10Some sldes are adapted from Pearson

Education

Page 11: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The Bus

Bus

• Keyboard notices that its name is on the Bus,and reads info. Other devices ignore the info.

CPU Keyboard Display

“Keyboard, did the user type anything?”

11Some sldes are adapted from Pearson

Education

Page 12: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The Bus

Bus

• Keyboard then writes “CPU: Yes, user typed ‘a’.” to Bus.

CPU Keyboard Display

“CPU: Yes, user typed ‘a’.”

12Some sldes are adapted from Pearson

Education

Page 13: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The Bus

Bus

• At some point, CPU reads the Bus, and gets the Keyboard’s response.

CPU Keyboard Display

“CPU: Yes, user typed ‘a’.”

13Some sldes are adapted from Pearson

Education

Page 14: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Computer Architecture

Bus

CPU

RAM

Keyboard

HardDisk

Display

CD-ROM

14Some sldes are adapted from Pearson

Education

Page 15: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Inside the CPU

• The CPU is the brain of the computer.

• It is the part that actually executes the instructions.

• Let’s take a look inside.

15Some sldes are adapted from Pearson

Education

Page 16: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

CPU and main memory connected via a bus

16Some slides are adapted from Pearson Education

General purpose register

Special purpose register

Page 17: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Inside the CPU (cont.)

Memory Registers

Register 0

Register 1

Register 2

Register 3

Instruction Register

Program counter

Arithmetic/ LogicUnit

To hold the address of the current

instruction in RAM17

Some sldes are adapted from Pearson Education

To hold the currentinstruction

Control Unit(State Machine)

Page 18: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Stored Program Concept

• A program can be encoded as bit patterns andstored in main memory.

• From there, the CPU can then extract theinstructions and execute them.

• In turn, the program to be executed can bealtered easily.

18Some sldes are adapted from Pearson

Education

Page 19: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Terminology

• Machine instruction: An instruction (or command)encoded as a bit pattern recognizable by the CPU

• Machine language: The set of all instructionsrecognized by a machine

19Some sldes are adapted from Pearson

Education

Page 20: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Machine Language Philosophies

• Reduced Instruction Set Computing (RISC)

– Few, simple, efficient, and fast instructions

– Examples: PowerPC from Apple/IBM/Motorola and ARM

• Complex Instruction Set Computing (CISC)

– Many, convenient, and powerful instructions

– Example: Intel

20Some sldes are adapted from Pearson

Education

Page 21: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Machine Instruction Types

• Data Transfer: copy data from one location to another

• Arithmetic/Logic: use existing bit patterns to compute a new bit patterns

• Control: direct the execution of the program

21Some sldes are adapted from Pearson

Education

Page 22: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Adding values stored in memory

22Some sldes are adapted from Pearson

Education

Page 23: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Dividing values stored in memory

23Some sldes are adapted from Pearson

Education

Page 24: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The architecture of the machine described in Appendix C

24Some sldes are adapted from Pearson

Education

Page 25: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Parts of a Machine Instruction

• Op-code: Specifies which operation to execute

• Operand: Gives more detailed information about the operation

– Interpretation of operand varies depending on op-code

25Some sldes are adapted from Pearson

Education

Page 26: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Typical Assembly Instructions

1. LOAD

2. LOAD directly

3. STORE

4. MOVE

5. ADD

6. ADD (floating point)

7. OR

8. AND

9. XOR

10. ROTATE

11. JMUP

12. HALT26

Some sldes are adapted from Pearson Education

Page 27: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The composition of an instruction for the machine in Appendix C

27Some sldes are adapted from Pearson

Education

Page 28: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Decoding the instruction 35A7

28Some sldes are adapted from Pearson

Education

Page 29: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

29

Page 30: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Program Execution

• Controlled by two special-purpose registers– Program counter: address of next instruction

– Instruction register: current instruction

• Machine Cycle– Fetch

– Decode

– Execute

30Some sldes are adapted from Pearson

Education

Page 31: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The machine cycle

31Some sldes are adapted from Pearson

Education

Page 32: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

The program stored in main memory ready for execution

32Some sldes are adapted from Pearson

Education

Page 33: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Performing the fetch step of the machine cycle

33Some sldes are adapted from Pearson

Education

Page 34: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Performing the fetch step of the machine cycle (cont’d)

34Some sldes are adapted from Pearson

Education

Page 35: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

A Simple Program

• Want to add values of variables a and b(assumed to be in memory), and put the result in variable c in memory, I.e. c a+b

• Instructions in program– Load a into register r1

– Load b into register r3

– r2 r1 + r3

– Store r2 in c

35Some sldes are adapted from Pearson

Education

Page 36: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Running the Program

a

c

2

1

3

Memory

Load a into r1

Load b into r3

r2 r1 + r3

Store r2 into c

20052006

2007

2008

2005

Load a into r1

r1

r2

r3

r4

IRIP

Logic

CPU

2

b

36Some sldes are adapted from Pearson

Education

Page 37: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Running the Program

a

c

2

1

3

Memory

Load a into r1

Load b into r3

r2 r1 + r3

Store r2 into c

20052006

2007

2008

2006

Load b into r3

r1

r2

r3

r4

IRIP

Logic

CPU

3

b

2

37Some sldes are adapted from Pearson

Education

Page 38: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Running the Program

a

c

2

1

3

Memory

Load a into r1

Load b into r3

r2 r1 + r3

Store r2 into c

20052006

2007

2008

2007

r2 r1 + r3

r1

r2

r3

r4

IRIP

Logic

CPU

3

b

2

5

38Some sldes are adapted from Pearson

Education

Page 39: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Running the Program

a

c

2

1

3

Memory

Load a into r1

Load b into r3

r2 r1 + r3

Store r2 into c

20052006

2007

2008

2008

Store r2 into c

r1

r2

r3

r4

IRIP

Logic

CPU

3

b

2

5

39Some sldes are adapted from Pearson

Education

Page 40: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Running the Program

a

c

2

5

3

Memory

Load a into r1

Load b into r3

r2 r1 + r3

Store r2 into c

20052006

2007

2008

2008

Store r2 into c

r1

r2

r3

r4

IRIP

Logic

CPU

3

b

2

5

40Some sldes are adapted from Pearson

Education

Page 41: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Arithmetic/Logic Operations

• Logic: AND, OR, XOR

– Masking

• Rotate and Shift

• Arithmetic: add, subtract, multiply, divide

41Some sldes are adapted from Pearson

Education

Page 42: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Rotating the bit pattern 65 (hexadecimal) one bit to the right

42Some sldes are adapted from Pearson

Education

Page 43: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Communicating with Other Devices

• Controller: An intermediary apparatus that handlescommunication between the computer and a device

– Specialized controllers for each type of device

– General purpose controllers (USB and FireWire)

• Port: The point at which a device connects to acomputer

• Memory-mapped I/O: CPU communicates withperipheral devices as though they were memory cells

43Some sldes are adapted from Pearson

Education

Page 44: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Figure 2.13 Controllers attached to a machine’s bus

44Some sldes are adapted from Pearson

Education

Page 45: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

A conceptual representation of memory-mapped I/O

45Some sldes are adapted from Pearson

Education

Page 46: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Communicating with Other Devices (continued)

• Direct memory access (DMA): Controller accessmain memory directly over the bus

• Von Neumann Bottleneck: Insufficient bus speedimpedes performance– CPU and controller compete the bus

• Handshaking: The process of coordinating thetransfer of data between components– Computer and device exchange information about the

device’s status and coordinate their activities

46Some sldes are adapted from Pearson

Education

Page 47: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Putting it all together

• We learned about

o Architecture of computer

o Components of CPU

o Program counter and instruction register

o Machine language using encoded bit patterns

o Machine cycle

o Op code and operand info

o Communication with other peripherals

47Some sldes are adapted from Pearson

Education

Page 48: Chapter 2 Data Manipulation - James Madison University · Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor ... Machine Instruction Types •Data Transfer: copy data

Question

Direct to [email protected]

48Some sldes are adapted from Pearson

Education