1 / 71

Topic 3 : Controlling the Computer

Topic 3 : Controlling the Computer. Machine Language/Machine Code Reference : G & L pp 159-169. A Quick Reminder of Microcode. Micromemory. Microinstruction. address. 0 + 0->MDR; MPC + 1 -> MPC;. 0. MPC + TESTZERO(A) -> MPC. 1.

Download Presentation

Topic 3 : Controlling the Computer

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. Topic 3 : Controlling the Computer Machine Language/Machine Code Reference : G & L pp 159-169

  2. A Quick Reminder of Microcode Micromemory Microinstruction address 0 + 0->MDR; MPC + 1 -> MPC; 0 MPC + TESTZERO(A) -> MPC 1 2 5 -> MPC C + MDR -> MDR; MPC + 1 -> MPC; 3 A - 1 -> A; 0 + 1 -> MPC 4 0 + 1 -> MAR; write; MPC + 1 -> MPC 5

  3. The Microprogram in Full Microinstruction 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 1 1 1 0 1 1 1 1 1 1 2 Micromemory address 1 1 1 1 1 3 1 1 1 1 1 4 1 1 1 1 1 5

  4. Evaluation of Microinstructions • Writing programs in microcode is very difficult: • cf code required to multiply two numbers • each instruction performs only a very small task. • instructions are closely tied to machine architecture. • instructions must be coded in binary.

  5. Providing More Support • If we are going to write big programs we need to provide programmers with easier to use and more powerful instructions. • Simplest languages which offer such support are called machine languages. • still at a very low level but much easier to use than microcode. • they introduce limited abstractions over the machine’s hardware, e.g. the accumulator.

  6. Overview of a Simple Machine Language • Simple language involving only 11 instructions. • Main abstraction is the accumulator which stores operands and results of arithmetic operations. • Why? - Because arithmetic operations often use the result of a preceding operation as an operand.

  7. Operations 1 & 2 • Load • moves values from memory to the accumulator. • LOAD 123 • Store • moves values from the accumulator into memory. • STORE 123

  8. Example: LOAD 103 100 ABC LOAD 103 101 DEF 102 GHI Accumulator 103 JKL 104 MNO 105 PQR STU 106 VWX 107

  9. Example: LOAD 103 100 ABC LOAD 103 101 DEF 102 GHI Accumulator 103 JKL 104 JKL MNO 105 PQR STU 106 VWX 107

  10. Example: STORE 103 100 ABC STORE 103 101 DEF 102 GHI Accumulator 103 JKL 104 AAA MNO 105 PQR STU 106 VWX 107

  11. Example: STORE 103 100 ABC STORE 103 101 DEF 102 GHI Accumulator 103 AAA 104 AAA MNO 105 PQR STU 106 VWX 107

  12. Operations 3,4,5 & 6 • Add • Adds the value from memory to the accumulator. • ADD 123 • Subtract • Subtracts the value from memory from the accumulator. • SUBTRACT 123 • Multiply • MULTIPLY 123 • Divide • DIVIDE 123

  13. The Machine Language So Far Operation Explanation LOAD M -> ACC STORE ACC -> M ADD ACC + M -> ACC SUBTRACT ACC - M -> ACC MULTIPLY ACC * M -> ACCDIVIDE ACC / M -> ACC

  14. Control Transfer (Ops 7,8 & 9) • Unconditional transfer of control. • JUMP M : Start executing instruction at memory cell M. • Conditional transfer of control • JUMPZERO M : Start executing instruction at memory cell M if the accumulator contains zero. • JUMPMSB M : Start executing instruction at memory cell M if the msb of the accumulator = 1.

  15. The Machine Language So Far Operation Explanation LOAD M -> ACC STORE ACC -> M ADD ACC + M -> ACC SUBTRACT ACC - M -> ACC MULTIPLY ACC * M -> ACCDIVIDE ACC / M -> ACC JUMP Jump to cell M JUMPZERO Jump if ACC = 0 JUMPMSB Jump if msb = 1

  16. Op Codes and Operands • We need to identify each instruction by giving it an op-code. • We use 4 bits because we have 11 instructions. • We also need to store the address of the operand. 0001000 000 000001 Operand Op-code

  17. The Machine Language So Far opcode adss Operation Explanation 0001 0010 0011 0100 0101 0110 0111 1000 1001 LOAD M -> ACC STORE ACC -> M ADD ACC + M -> ACC SUBTRACT ACC - M -> ACC MULTIPLY ACC * M -> ACCDIVIDE ACC / M -> ACC JUMP Jump to cell M JUMPZERO Jump if ACC = 0 JUMPMSB Jump if msb = 1

  18. An Example Address Op Code Operand Addr Instruction • Calculates x*x where x is initially in location 5. • Compare this with its microcode program. 1 1005 1 5 2 5005 5 5 3 2005 2 5 4 FFFF 5 000A

  19. An Example ACC : 0 Address Instruction • Calculates x*x where x is initially in location 5. • Compare this with its microcode program. 1 1005 2 5005 3 2005 4 FFFF 5 000A

  20. An Example ACC : A Address Instruction • Calculates x*x where x is initially in location 5. • Compare this with its microcode program. 1 1005 LOAD 5 -> ACC 2 5005 3 2005 4 FFFF 5 000A

  21. An Example ACC : 64 Address Instruction • Calculates x*x where x is initially in location 5. • Compare this with its microcode program. 1 1005 Contents 5 -> ACC 2 5005 ACC * Contents 5 -> ACC 3 2005 4 FFFF 5 000A

  22. An Example ACC : 64 Address Instruction • Calculates x*x where x is initially in location 5. • Compare this with its microcode program. 1 1005 Contents 5 -> ACC 2 5005 ACC * Contents 5 -> ACC 3 2005 Contents of Acc -> 5 4 FFFF 5 0064

  23. An Example ACC : 64 Address Instruction • Calculates x*x where x is initially in location 5. • Compare this with its microcode program. 1 1005 Contents 5 -> ACC 2 5005 ACC * Contents 5 -> ACC 3 2005 Contents of Acc -> 5 4 FFFF Stop 5 0064

  24. A Further Example Address Instruction 1 100D 2 200C 3 100B 4 800E 5 400D 6 200B 7 100C 8 300C 9 200C 10 7003 11 1 12 0 13 1

  25. A Further Example ACC : 1 Address Instruction 1 100D Contents 13 -> ACC 2 200C 3 100B 4 800E 5 400D 6 200B 7 100C 8 300C 9 200C 10 7003 11 1 12 0 13 1

  26. A Further Example Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B 4 800E 5 400D 6 200B 7 100C 8 300C 9 200C 10 7003 11 1 12 1 13 1

  27. A Further Example ACC : 1 Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E 5 400D 6 200B 7 100C 8 300C 9 200C 10 7003 11 1 12 1 13 1

  28. A Further Example Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D 6 200B 7 100C 8 300C 9 200C 10 7003 11 1 12 1 13 1

  29. A Further Example ACC : 0 Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D ACC - Contents 13 -> ACC 6 200B 7 100C 8 300C 9 200C 10 7003 11 1 12 1 13 1

  30. A Further Example Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D ACC - Contents 13 -> ACC 6 200B Store ACC -> 11 7 100C 8 300C 9 200C 10 7003 11 0 12 1 13 1

  31. A Further Example ACC : 1 Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D ACC - Contents 13 -> ACC 6 200B Store ACC -> 11 7 100C Contents 12 -> ACC 8 300C 9 200C 10 7003 11 0 12 1 13 1

  32. A Further Example ACC : 2 Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D ACC - Contents 13 -> ACC 6 200B Store ACC -> 11 7 100C Contents 12 -> ACC 8 300C ACC + Contents 12 -> ACC 9 200C 10 7003 11 0 12 1 13 1

  33. A Further Example Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D ACC - Contents 13 -> ACC 6 200B Store ACC -> 11 7 100C Contents 12 -> ACC 8 300C ACC + Contents 12 -> ACC 9 200C ACC -> 12 10 7003 11 0 12 2 13 1

  34. A Further Example Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D ACC - Contents 13 -> ACC 6 200B Store ACC -> 11 7 100C Contents 12 -> ACC 8 300C ACC + Contents 12 -> ACC 9 200C ACC -> 12 10 7003 Jump 3 11 0 12 2 13 1

  35. A Further Example ACC : 0 Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D ACC - Contents 13 -> ACC 6 200B Store ACC -> 11 7 100C Contents 12 -> ACC 8 300C ACC + Contents 12 -> ACC 9 200C ACC -> 12 10 7003 Jump 3 11 0 12 2 13 1

  36. A Further Example Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D ACC - Contents 13 -> ACC 6 200B Store ACC -> 11 7 100C Contents 12 -> ACC 8 300C ACC + Contents 12 -> ACC 9 200C ACC -> 12 10 7003 Jump 3 11 0 12 2 13 1

  37. A Further Example Address Instruction 1 100D Contents 13 -> ACC 2 200C ACC -> 12 3 100B Contents 11 -> ACC 4 800E Jump to 14 if ACC 0 5 400D ACC - Contents 13 -> ACC 6 200B Store ACC -> 11 7 100C Contents 12 -> ACC 8 300C ACC + Contents 12 -> ACC 9 200C ACC -> 12 10 7003 Jump 3 11 0 -- holds x initially 12 2 -- ends up with y where y=2^x 13 1 -- holds value 1

  38. The Machine Language So Far opcode adss Operation Explanation 0001 0010 0011 0100 0101 0110 0111 1000 1001 LOAD M -> ACC STORE ACC -> M ADD ACC + M -> ACC SUBTRACT ACC - M -> ACC MULTIPLY ACC * M -> ACCDIVIDE ACC / M -> ACC JUMP Jump to cell M JUMPZERO Jump if ACC = 0 JUMPMSB Jump if msb = 1

  39. Modular Structure (Operations 10 & 11) • Two instructions not yet described, i.e. JUMPSUB and RETURN • These instructions may be used to structure programs, i.e. subroutines. • Equivalent to gosubs (BASIC) or function calls.

  40. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  41. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  42. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  43. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  44. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  45. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  46. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  47. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  48. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  49. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

  50. Modular Structure ... contd. instruction 1 instruction 2 instruction 3 JUMPSUB M instruction 5 instruction 6 JUMPSUB M instruction 8 instruction 9 M: does something does something else and something else RETURN M

More Related