Presentation is loading. Please wait.

Presentation is loading. Please wait.

Systems Environment 3 Quick Revision Review of Exercises Introduction to TOM TOM Exercises.

Similar presentations


Presentation on theme: "Systems Environment 3 Quick Revision Review of Exercises Introduction to TOM TOM Exercises."— Presentation transcript:

1 Systems Environment 3 Quick Revision Review of Exercises Introduction to TOM TOM Exercises

2 Quick Revision

3 Processor Instructions

4 Diagram 3 The CPU Level RAM Control UnitRegisters Arithmetic & Logic Unit The most Important of the registers is the Accumulator (ACC) ALL Data and Instructions must pass through the here. The most Important of the registers is the Accumulator (ACC) ALL Data and Instructions must pass through the here. Near the control unit is the Program Counter (PC) This indicates which instruction is currently being processed. Near the control unit is the Program Counter (PC) This indicates which instruction is currently being processed.

5 Processor Instruction Set Processor instructions are normally split into two parts: The Operation Code which is written to the IR The Operand which is written to the MRB IR Instruction Register MRB Memory Read Buffer Note that some instructions consist only of an Op Code, and do not require Operands. Op CodeOperand IRMRB

6 Instruction Types Instructions beginning STx These are instructions to STORE data at some RAM Memory Location Instructions beginning LDx These are instructions to LOAD Data into the Accumulator Instructions beginning ADx These are instructions to ADD data to the contents of the Accumulator

7 Instruction Types Instructions ending xxI These instructions use the Immediately following operand as the data Instructions ending xxD These instructions use the operand as an Address Directly to Access the data Instructions ending xxN These instructions use the operand as an address iNdirectly, to locate the address where the data is to be found.

8 Instruction Types Instructions not requiring an Operand: IN This inputs data into the processor from an external source OUT This outputs data to the VDU STP This stops the processor.

9 Examples LDI 34 STD 25 ADN 43 What precisely, do these instructions mean? What precisely, do these instructions mean?

10 Examples LDI 34 STD 25 ADN 43 Loads 34 Immediately into the Accumulator Stores the contents of the accumulator at memory address 25 Finds memory address 43, there goes to the location specified there. Takes the data at this second location and adds it to the value in the accumulator

11 More Instructions These instructions all divert processing to different locations in RAM: JMP xx The program counter changes to XX and processing continues from there. JZ xx If the Accumulator is Zero, the program counter changes to xx and processing continues from there. JMI xx If the Accumulator is Negative, the program counter changes to xx and continues processing from there. These commands work by changing the value in the PC

12 Activity 1 (Booklet, Exercise 5) 137 LDD 138 200 139 ADD 140 201 141 OUT 142 STD 143 200 144 LDD 145 202 146 SUB 147 203 148 STD 149 202 150 JZ 151 154 152 JMP 153 137 154 STP Translate this program into full instructions, Then execute the program, to see what effect it has. Translate this program into full instructions, Then execute the program, to see what effect it has.

13 Exercise 5 Solution (part 1) 137 LDD Load Directly 138 200from location 200 139 ADD Add Directly 140 201 from location 201 141 OUT Output 142 STD Store Directly 143 200in location 200 144 LDD Load Directly 145 202 from location 202 146 SUB Subtract (Directly) 147 203from location 203 148 STD Store Directly 149 202 in location 202 150 JZ If Accumulator Zero, Jump 151 154to instruction 154 152 JMP Jump 153 137to instruction 137 154 STP

14 Program Execution 200 0 201 5 202 10 203 1 204 0 AC OUT 137 LDD 138 200 139 ADD 140 201 141 OUT 142 STD 143 200 144 LDD 145 202 146 SUB 147 203 148 STD 149 202 150 JZ 151 154 152 JMP 153 137 154 STP

15 Exercise 5 Solution part 2 Final State of Registers 200 50 201 5 202 0 203 1 204 0 AC 0 OUT 50 137 LDD 138 200 139 ADD 140 201 141 OUT 142 STD 143 200 144 LDD 145 202 146 SUB 147 203 148 STD 149 202 150 JZ 151 154 152 JMP 153 137 154 STP

16 PseudoCode Commands Program (name) Begin do things End If (condition) Then do things Else do things Endif For Count = 1 to X do things EndFor While (condition) do things EndWhile Write (number) Read (number) A: = (something)

17 Exercise 5 Solution Part 3 Program CountUpInFives Begin Answer:= 0 Countdown:= 10 While Countdown <> 0 Answer: = Answer + 5 Write (Answer) Countdown: = Countdown – 1 EndWhile End This summarises what the program does in a more succinct manner.

18 Exercise 5.2 PseudoCode Program Pre_TOM Begin Read (Number) While Number <> 0 Write (Number) Read (Number) EndWhile End What is the machine level code for these instructions?

19 Exercise 5.2 Solution Program Pre_TOM Begin Read (Number) While Number <> 0 Write (Number) Read (Number) EndWhile End The program has been put into memory at location 200. This is completely arbitrary. 200 INP 201 JZ 202 206 203 OUT 204 JMP 205200 206STP

20 TOM Totally Obedient Moron

21 What is TOM? First of all, TOM is a CPU simulator which allows you to run short CPU programs and a lot more. You need to access H:/Tomfile and download all the files in the folder to your A: drive. Double-Click on TOM.exe and you will get this dialogue box.

22 RAM Memory Locations, where the program will be stored: Program Counter Accumulator Click-Able Keys to input, edit and clear Instructions. Output Device Control Buttons

23 Getting to know TOM Clicking ‘Help’ on the toolbar brings up this screen. After this session you should spend some reading the first 6 sections. Here we are going to dive straight in to the instruction Set (4 th on the list) TOM’s Instructions are very like (but not exactly the same as) the ones we have seen.

24 Tom’s Easy Instructions The following is a list of the first 12 of TOM’s instructions: 0 HALTHLT 1 LOAD ACCUMULATORLDA 2 STORE ACCUMULATOR STO 3 ADD TO ACCUMULATOR AC+ 4 SUBTRACT FROM ACCUMULATOR AC- 5 MULTIPLY ACCUMULATOR ACX 6 DIVIDE ACCUMULATORAC\ 7 JUMP UNCONDITIONALLYJMP 8 JUMP IF ACCUMULATOR NEGATIVEJM- 9 JUMP IF ACCUMULATOR IS ZEROJM0 10 JUMP INDIRECTJ() 11 INPUT A NUMBER TO ACCUMULATORINP 12 OUTPUT A NUMBER FROM THE ACCUMULATOROUT

25 Our First TOM Program At the top of the TOM window, click on: File – Open then select: wexampl1.tom from the menu. At the top of the TOM window, click on: File – Open then select: wexampl1.tom from the menu.

26 TOM Example 1 This is the disassembled version of the program. In order to see this, you should click on: Options – Disassemble NB: Assembled = “in Numerical form” Disassembled = “In mnemonic code form

27 Running Example 1 Run the Program. The yellow highlight will move down the screen. What else happens? RUN

28 Running Example 1 Program Counter shows 2 The program is now in Assembled form The value 55 has been printed out. Accumulator shows 55 So, what exactly did the program do?

29 What Example 1 Did: Loaded the value 55 into the Accumulator, from location 24 Output the value in the Accumulator to the Printer Stopped Processing.

30 TOM Example 2 Load in Example 2, and use the assembled (left) or the disassembled version (right). Say what effect each line will have. Trace through the program to work out what exactly will happen. Run the program to see if you were right.

31 TOM Example 2 Input a number from the Keypad into the Accumulator Store the number at location 12 Add the number stored at location 12 to the value in the Accumulator Output the value in the Accumulator to the printer Stop processing The task performed by the program was to add the two input numbers, and print out the answer.

32 TOM Challenge Try to create a program to do the following: Input two numbers from the Keypad into the Accumulator Store the numbers at locations 12 and 13 Subtract the second number entered from the first Output the answer Stop processing Work on paper first. When you feel that the program you have created is correct, then type it in and run it. Work on paper first. When you feel that the program you have created is correct, then type it in and run it.

33 TOM Challenge - solution 00Input a number 01Store at location 12 02Input a number 03Store at location 13 04Load acc from location 12 05Subtract value from location 13 from accumulator 06Output the value in the accumulator 07Halt Disassembled version Assembled version

34 Activity 4 You should now open in turn, Examples 3 and 4 from the disk. In each case you should: 1. Make a written copy of the program in disassembled form. 2. Explain what effect each line of the program will have 3. Trace through the program to see its effect on the accumulator, memory locations and output. 4. Run the program to see whether you are correct 5. Briefly summarize what task the program is performing. You may find it helpful to read TOM’s Help File (the first 6 sections)

35 Exercise 6.1 You are asked to write a pseudo code design for these specifications: Exercise 6.1.1 Input: Numbers from Keyboard Output: Each Number entered Termination: Zero

36 Input: Numbers from Keyboard Output: Each Number entered Termination: Zero Program Pre_TOM Begin Read (Number) While Number <> 0 Write (Number) Read (Number) EndWhile End In fact, this is precisely the program we saw in Exercise 5.2 We now need to change this to a TOM Program

37 6.1.1 TOM Solution The program is just the solution from ex.5.2 in terms of TOM’s instructions. It is a simple translation from one “dialect” of machine code to the other.

38 Activity Now work in groups to complete exercise 6 Intitially do parts 2-5 If you feel confident, you can go on to 6,7 and 8, but you may need to read the helpfile for more TOM commands.


Download ppt "Systems Environment 3 Quick Revision Review of Exercises Introduction to TOM TOM Exercises."

Similar presentations


Ads by Google