data manipulation, part two

30
Data Manipulation, Data Manipulation, part two part two Introduction to computer, 2 nd semester, 2010/2011 Mr.Nael Aburas [email protected] Faculty of Information Technology Islamic University of Gaza 1 Islamic University Of Gaza, Nael Aburas

Upload: slade-mclean

Post on 03-Jan-2016

23 views

Category:

Documents


0 download

DESCRIPTION

Data Manipulation, part two. Introduction to computer, 2 nd semester, 2010/2011 Mr.Nael Aburas [email protected] Faculty of Information Technology Islamic University of Gaza. Program execution. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Data Manipulation, part two

Data Manipulation, part Data Manipulation, part twotwo

Introduction to computer, 2nd semester, 2010/2011Mr.Nael Aburas [email protected] of Information TechnologyIslamic University of Gaza

1Islamic University Of Gaza, Nael Aburas

Page 2: Data Manipulation, part two

Program executionProgram executionA computer follows a program stored in

its memory by copying the instructions from a memory into the CPU as needed.

To understand how the overall execution process takes place, it is necessary to consider two of the special purpose registers within the CPU:◦ Instruction register◦ Program counter

2Islamic University Of Gaza, Nael Aburas

Page 3: Data Manipulation, part two

Program executionProgram execution Instruction registercontains the instruction that is

currently being executed (current instruction)

Program countercontains the address of the next

instruction to be executed. (next instruction)

3Islamic University Of Gaza, Nael Aburas

Page 4: Data Manipulation, part two

Machine cycleMachine cycle

For every instruction, a processor repeats a set of basic operations, which comprise a machine cycle◦Fetch◦Decode ◦execute

4Islamic University Of Gaza, Nael Aburas

Page 5: Data Manipulation, part two

The machine cycleThe machine cycle

2-5Islamic University Of Gaza, Nael Aburas

Page 6: Data Manipulation, part two

FetchFetch◦The CPU requests the main memory

to provide it with the instruction that is stored at the address indicated by the program counter.

◦The CPU places the instruction received form memory in its instruction register and then increments the program counter.

◦The program counter will be ready for the next fetch.

6Islamic University Of Gaza, Nael Aburas

Page 7: Data Manipulation, part two

Decode & Execute Decode & Execute Decode Breaking the operand filed into its

proper components based on the instruction's op-code.

The CPU then executes the instruction by activating the appropriate circuitry to perform the requested task.

Once the instruction in the instruction register has been executed, the CPU again begins the machine cycle with the fetch step

7Islamic University Of Gaza, Nael Aburas

Page 8: Data Manipulation, part two

Machine cycleMachine cycle Sometimes Special case is the execution

of a JUMP instruction. Example, figure 2.9, which means “JUMP to the instruction at address 58 if the contents of register 2 is the same as that of register 0.

If they contain different bit patterns, the execute step terminates and the next machine cycle begins.

If equal, the machine places the value 58 in its program counter during the execute step, then , then next fetch step finds 58 in the program counter, so the instruction at that address will be the next instruction to be fetched and executed.

8Islamic University Of Gaza, Nael Aburas

Page 9: Data Manipulation, part two

Figure 2.9 Decoding the Figure 2.9 Decoding the instruction B258instruction B258

2-9Islamic University Of Gaza, Nael Aburas

Page 10: Data Manipulation, part two

Example of program Example of program executionexecution

The example that will be described bellow is about adding two values and store the result.

First we need to store the program somewhere in the memory.

Suppose that the program is stored in addresses, starting at address A0 (hexadecimal).

We can cause the machine to execute it by placing the address (A0) of the first instruction in the program counter and starting the machine (Figure 2.10)

10Islamic University Of Gaza, Nael Aburas

Page 11: Data Manipulation, part two

Figure 2.10 The program from Figure 2.7 Figure 2.10 The program from Figure 2.7 stored in main memory ready for stored in main memory ready for executionexecution

2-11Islamic University Of Gaza, Nael Aburas

Page 12: Data Manipulation, part two

Example of program Example of program executionexecutionThe CPU begins the fetch step by

extracting the instruction stored in main memory at location A0 and plain it in the instruction register (Figure 2.11a).

Notice that in the machine, instruction are 16 bits long. Thus the entire instruction to be fetched occupies the memory cells at both address A0 and A1, the CPU is designed to take this into account.

12Islamic University Of Gaza, Nael Aburas

Page 13: Data Manipulation, part two

Example of program Example of program executionexecutionThe CPU then adds two to the program

counter so that this register contains the address of the next instruction (Figure 2.11b).

Next, the CPU decode “analyzes” the instruction in its instruction register and concludes that it is to load register 5 with the contents of the memory cell at address 6C. This load is performed during the execution step of the machine cycle, and then the CPU begins the next cycle. And so on.

13Islamic University Of Gaza, Nael Aburas

Page 14: Data Manipulation, part two

Figure 2.11 Performing the fetch step of Figure 2.11 Performing the fetch step of the machine cyclethe machine cycle

2-14Islamic University Of Gaza, Nael Aburas

Page 15: Data Manipulation, part two

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

15Islamic University Of Gaza, Nael Aburas

Page 16: Data Manipulation, part two

Exercise 1 Exercise 1 Suppose that the memory cells from address 00 to 05

in the machine described in appendix C contain the (hexadecimal) bit patterns given in the following table

If we start the machine with its program counter containing 00, what bit pattern is in the memory cell whose address is hexadecimal 17 when the machine halts? Address contents

00 14

01 02

02 34

03 17

04 C0

05 00

16Islamic University Of Gaza, Nael Aburas

Page 17: Data Manipulation, part two

Exercise 2Exercise 2 Suppose that the memory cells from address B0 to B8

in the machine described in appendix C contain the (hexadecimal) bit patterns given in the following table

If the program counter starts at B0, what bit pattern is in register number 3 after the first instruction has been executed?

What bit pattern is in memory cell B8 when the halt instruction is executed?

17Islamic University Of Gaza, Nael Aburas

Page 18: Data Manipulation, part two

Exercise 2, (Cont’d)Exercise 2, (Cont’d)

Address contents

B0 13

B1 B8

B2 A3

B3 02

B4 33

B5 B8

B6 C0

B7 00

B8 0F

18Islamic University Of Gaza, Nael Aburas

Page 19: Data Manipulation, part two

Arithmetic/logic instructionsArithmetic/logic instructions

As mentioned before, the arithmetic/logic group of instructions consists of instructions requesting arithmetic, logic, and shift operations

19Islamic University Of Gaza, Nael Aburas

Page 20: Data Manipulation, part two

Logic operationsLogic operations We introduced the logic AND, OR,

XOR in chapter1. these operations can be extended to operations that combine two strings of bits to produce a single output string.

Example:100110101100100110001000

AND

20Islamic University Of Gaza, Nael Aburas

Page 21: Data Manipulation, part two

Logic operationsLogic operationsOne of the major uses of the AND operation is

for placing 0s in one part of the bit pattern. For example: 00001111 is the first operand of the AND operation. Without knowing the content of the second operand, we still can conclude that the four most significant bits of the result will be 0s, and the four least significant bits will be copy of that part of the second operand.

000011111010101000001010

AND

21Islamic University Of Gaza, Nael Aburas

Page 22: Data Manipulation, part two

Logic operationsLogic operationsThis use of AND is an example of maskingMask: determine which part of the other

operand will effect the resultExample: the mask11011111 can be used to

with the AND operation to force a 0 in the third bit from the high-order end of byte.

The mask 00100000 can be used with OR operation to force a 1 in that position. (OR is used for placing 1 in somewhere in the byte.), ( the OR operation can be used to duplicate a part of string while putting 1s in the no duplicated position “other part”)

22Islamic University Of Gaza, Nael Aburas

Page 23: Data Manipulation, part two

Logic operationsLogic operationsA major use for XOR operation is

in forming the complement of the byte. For example, the relation between the second operand and the result as following:

111111111010101001010101

XOR

23Islamic University Of Gaza, Nael Aburas

Page 24: Data Manipulation, part two

Exercise 3 Exercise 3 Suppose you want to isolate the

middle four bits of a byte by placing 0s in the other four bit without disturbing the middle four bits. What mask must you use together with what operation?

24Islamic University Of Gaza, Nael Aburas

Page 25: Data Manipulation, part two

Exercise 3, Answer Exercise 3, Answer The mask is 00111100, with the

AND operation

25Islamic University Of Gaza, Nael Aburas

Page 26: Data Manipulation, part two

Exercise 4Exercise 4Using the machine language of

appendix C, write a program that places a 1 in the most significant bit of the memory cell whose address is A7without modifying the remaining bits in the cell.

26Islamic University Of Gaza, Nael Aburas

Page 27: Data Manipulation, part two

Exercise 4, AnswerExercise 4, Answer12A7 (load register 2 with the

content of memory cell A7)2380 (load register 3 with the

value 80)7023 (OR register2 and 3 leaving

the result in register 0)30A7 (STORE contents of register

0 n memory cell A7)C000 (Halt)

27Islamic University Of Gaza, Nael Aburas

Page 28: Data Manipulation, part two

Rotation and shift Rotation and shift operationoperationThe operations Rotation and sift

provide a means for moving bits within a register

These operations are classified by the direction of motion (right or left).

28Islamic University Of Gaza, Nael Aburas

Page 29: Data Manipulation, part two

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

29Islamic University Of Gaza, Nael Aburas

Page 30: Data Manipulation, part two

Rotation and shift Rotation and shift operationoperationAnother technique is to discard

the bit that falls of and always fill the hole with 0, the term logical shift is used to refer to this technique.

30Islamic University Of Gaza, Nael Aburas