1 / 30

Data Manipulation, part two

Data Manipulation, part two. Introduction to computer, 2 nd semester, 2010/2011 Mr.Nael Aburas nras@iugaza.edu.ps Faculty of Information Technology Islamic University of Gaza. Program execution.

Download Presentation

Data Manipulation, part two

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Manipulation, part two Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas nras@iugaza.edu.ps Faculty of Information Technology Islamic University of Gaza Islamic University Of Gaza, Nael Aburas

  2. Program execution • A 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 Islamic University Of Gaza, Nael Aburas

  3. Program execution • Instruction register • contains the instruction that is currently being executed (current instruction) • Program counter • contains the address of the next instruction to be executed. (next instruction) Islamic University Of Gaza, Nael Aburas

  4. Machine cycle For every instruction, a processor repeats a set of basic operations, which comprise a machine cycle • Fetch • Decode • execute Islamic University Of Gaza, Nael Aburas

  5. The machine cycle Islamic University Of Gaza, Nael Aburas

  6. Fetch • 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. Islamic University Of Gaza, Nael Aburas

  7. 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 Islamic University Of Gaza, Nael Aburas

  8. Machine 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. Islamic University Of Gaza, Nael Aburas

  9. Figure 2.9 Decoding the instruction B258 Islamic University Of Gaza, Nael Aburas

  10. Example of program execution • 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) Islamic University Of Gaza, Nael Aburas

  11. Figure 2.10 The program from Figure 2.7 stored in main memory ready for execution Islamic University Of Gaza, Nael Aburas

  12. Example of program execution • The 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. Islamic University Of Gaza, Nael Aburas

  13. Example of program execution • The 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. Islamic University Of Gaza, Nael Aburas

  14. Figure 2.11 Performing the fetch step of the machine cycle Islamic University Of Gaza, Nael Aburas

  15. Figure 2.11 Performing the fetch step of the machine cycle (cont’d) Islamic University Of Gaza, Nael Aburas

  16. 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? Islamic University Of Gaza, Nael Aburas

  17. Exercise 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? Islamic University Of Gaza, Nael Aburas

  18. Exercise 2, (Cont’d) Islamic University Of Gaza, Nael Aburas

  19. Arithmetic/logic instructions • As mentioned before, the arithmetic/logic group of instructions consists of instructions requesting arithmetic, logic, and shift operations Islamic University Of Gaza, Nael Aburas

  20. Logic 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: 10011010 11001001 10001000 AND Islamic University Of Gaza, Nael Aburas

  21. Logic operations • One 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. 00001111 10101010 00001010 AND Islamic University Of Gaza, Nael Aburas

  22. Logic operations • This use of AND is an example of masking • Mask: determine which part of the other operand will effect the result • Example: 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”) Islamic University Of Gaza, Nael Aburas

  23. Logic operations • A 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: 11111111 10101010 01010101 XOR Islamic University Of Gaza, Nael Aburas

  24. 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? Islamic University Of Gaza, Nael Aburas

  25. Exercise 3, Answer • The mask is 00111100, with the AND operation Islamic University Of Gaza, Nael Aburas

  26. Exercise 4 • Using 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. Islamic University Of Gaza, Nael Aburas

  27. Exercise 4, Answer • 12A7 (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) Islamic University Of Gaza, Nael Aburas

  28. Rotation and shift operation • The 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). Islamic University Of Gaza, Nael Aburas

  29. Figure 2.12 Rotating the bit pattern 65 (hexadecimal) one bit to the right Islamic University Of Gaza, Nael Aburas

  30. Rotation and shift operation • Another 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. Islamic University Of Gaza, Nael Aburas

More Related