1 / 50

Topic 3 : Controlling the Computer

Topic 3 : Controlling the Computer. More Machine Language & Assembly Language Reference : G & L pp 168 but note that most of the material isn’t in G & L. http://info.comp.lancs.ac.uk. Addressing Modes. In previous examples the instructions have had the address of their operand hard-wired.

bowen
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 More Machine Language & Assembly Language Reference : G & L pp 168 but note that most of the material isn’t in G & L. http://info.comp.lancs.ac.uk

  2. Addressing Modes • In previous examples the instructions have had the address of their operand hard-wired. • Load 5 : 1005 • Store 5 : 2005 • Such a restriction makes it difficult to perform routine tasks such as:- • dealing with constants. • processing arrays. • dealing with complex data structures.

  3. Addressing Modes • Solution is to provide support for common addressing requirements by introducing more powerful addressing modes. • Direct • Immediate • Indexed • Indirect

  4. Direct Addressing • Copies the value stored at the specified address into the accumulator. • Used for accessing stored data. LOAD 10

  5. Immediate Addressing • Copies the operand into the accumulator. • Used for dealing with constants. LOAD #10

  6. Indexed Addressing • Introduces a new register called the index register. • Effective address = the operand field + the value in the index register. • Used for processing arrays LOAD +10

  7. Indirect Addressing • The operand specifies the address of the address of the data. • Used for handling complex data structures. LOAD @10

  8. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 110 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  9. Examples ofAddressing Modes ACC : 110 110 210 111 212 Load Immediate 110 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  10. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 110 Load Direct 110 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  11. Examples ofAddressing Modes ACC : 210 110 210 111 212 Load Immediate 110 Load Direct 110 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  12. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 110 Load Direct 110 Load Indexed 110 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  13. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 110 Load Direct 110 Load Indexed 110 + 2 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  14. Examples ofAddressing Modes ACC : 7 110 210 111 212 Load Immediate 110 Load Direct 110 Load Indexed 110 + 2 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  15. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 110 Load Direct 110 Load Indexed 110 + 2 Load Indirect 110 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  16. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 110 Load Direct 110 Load Indexed 110 + 2 Load Indirect 110 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  17. Examples ofAddressing Modes ACC : 10 110 210 111 212 Load Immediate 110 Load Direct 110 Load Indexed 110 + 2 Load Indirect 110 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  18. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 111 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  19. Examples ofAddressing Modes ACC : 111 110 210 111 212 Load Immediate 111 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  20. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 111 Load Direct 111 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  21. Examples ofAddressing Modes ACC : 212 110 210 111 212 Load Immediate 111 Load Direct 111 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  22. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 111 Load Direct 111 Load Indexed 111 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  23. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 111 Load Direct 111 Load Indexed 111 + 2 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  24. Examples ofAddressing Modes ACC : 8 110 210 111 212 Load Immediate 111 Load Direct 111 Load Indexed 111 + 2 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  25. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 111 Load Direct 111 Load Indexed 111 + 2 Load Indirect 111 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  26. Examples ofAddressing Modes ACC : 0 110 210 111 212 Load Immediate 111 Load Direct 111 Load Indexed 111 + 2 Load Indirect 111 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  27. Examples ofAddressing Modes ACC : 12 110 210 111 212 Load Immediate 111 Load Direct 111 Load Indexed 111 + 2 Load Indirect 111 112 7 8 113 114 9 ..... 10 210 11 211 12 212 213 13 214 14 Index 2

  28. Relocating Code: The Base Register • If we want to run more than one program at a time we need to be able to relocate programs. • If we can’t then we’d have to write every single program such that they all used different addresses. • Hardware support for relocation can be provided in the form of a base register. • Value in the base register is added to each operand before address resolution.

  29. The Base Register in Action 110 AAA Program A 111 BBB Base Register 112 CCC Load 10 Store 12 100 DDD 113 114 EEE ..... Accumulator Program B FFF 210 GGG 211 Load 10 Store 12 HHH 212 213 III 214 JJJ

  30. The Base Register in Action 110 AAA Program A 111 BBB Base Register 112 CCC Load 10 Store 12 100 DDD 113 114 EEE ..... Accumulator Program B FFF 210 GGG 211 Load 10 Store 12 AAA HHH 212 213 III 214 JJJ

  31. The Base Register in Action 110 AAA Program A 111 BBB Base Register 112 AAA Load 10 Store 12 100 DDD 113 114 EEE ..... Accumulator Program B FFF 210 GGG 211 Load 10 Store 12 AAA HHH 212 213 III 214 JJJ

  32. The Base Register in Action 110 AAA Program A 111 BBB Base Register 112 AAA Load 10 Store 12 200 DDD 113 114 EEE ..... Accumulator Program B FFF 210 GGG 211 Load 10 Store 12 FFF HHH 212 213 III 214 JJJ

  33. The Base Register in Action 110 AAA Program A 111 BBB Base Register 112 AAA Load 10 Store 12 200 DDD 113 114 EEE ..... Accumulator Program B FFF 210 GGG 211 Load 10 Store 12 FFF FFF 212 213 III 214 JJJ

  34. Protecting Programs From Each Other • If multiple programs are running we can check that they stay in their own sections of memory using a limit register. • Each store access is then checked against the limit register to ensure that it is within the programs allocated store.

  35. Multiple Index Registers and Accumulators • We have assumed a single accumulator and a single index register. • Some computers have multiple accumulators and index registers. • We simply need to introduce an extra parameter to the operation to specify which accumulator/index register to use. • In practice many computers don’t distinguish between types of register.

  36. Problems with Machine Code • Large difference between the statement of a typical problem and its solution in machine code. • We have to convert all our operations and addresses into binary or hex patterns. • Every time we change the program we have to recalculate all the jump and data addresses. • Solution: use a higher-level language.

  37. Languages in a Computer System hardware

  38. Languages in a Computer System microprogrammed interpreter hardware

  39. Languages in a Computer System machine code microprogrammed interpreter hardware

  40. Languages in a Computer System Assembly translators machine code microprogrammed interpreter hardware

  41. Languages in a Computer System Systems Assembly translators translators machine code microprogrammed interpreter hardware

  42. Languages in a Computer System General Purpose Systems Assembly translators translators translators machine code microprogrammed interpreter hardware

  43. Assembly Languages • Assembly languages are low-level languages which are very close to machine code. • In general one assembly language instruction = 1 machine code instruction. • Better support for operations: use mnemonics to make writing & understanding code easier. • Better support for data: provides support for writing code without having to hard-wire addresses into the code.

  44. An Assembly Language • Each statement has four fields:- • a label field, a symbol to represent the address of the instruction or data. • an operation field which holds the name of an instruction. • an operand field with optional symbols to denote addressing modes. • a comment field.

  45. An Assembly Language ... contd. label: operation mode operand comment

  46. An Assembly Language ... contd. label: operation mode operand comment here: LDA # 50 ; load 50 into acc there: STA 50 ; store A into loc. 50 JMP there

  47. An Array Processing Program LDA #50 STA COUNT ; store iteration count LDA #0 STI ; set index register to 0 STA TEMP ; initialise sum of elements TOP: LDA TEMP ADD ARRAY+ STA TEMP ; add the next value LDI ADD #1 STI LDA COUNT SUB #1 STA COUNT JNZ TOP

  48. Assessment of Languages Covered • Microcode • easy to build computers to execute microcode. • difficult to program in because instructions do too little. • Machine code • easier to use than microcode. • difficult to write flexible code, programmers must work in hex & instructions still do very little. • Assembly Language • more powerful and flexible then machine code or microcode. • lack of portability and still a long way from the problem.

  49. Summary • Described extensions to our machine code’s addressing scheme to make it more powerful. • Covered the relationship between high-level languages and machine languages/code in the system. • Described a simple assembly language. • Evaluated those languages which we have met so far.

  50. Coming Next Week • A look at how the computer can interact with the outside world. • G & L pp 169-172. • http://info.comp.lancs.ac.uk

More Related