Presentation is loading. Please wait.

Presentation is loading. Please wait.

Branching on Zero A Worked Example. Branching on Zero Countdown from 99 to 1, then stop Cell Code Description 00LDA Load from … 0110 … cell 10 02OUT Output.

Similar presentations


Presentation on theme: "Branching on Zero A Worked Example. Branching on Zero Countdown from 99 to 1, then stop Cell Code Description 00LDA Load from … 0110 … cell 10 02OUT Output."— Presentation transcript:

1 Branching on Zero A Worked Example

2 Branching on Zero Countdown from 99 to 1, then stop Cell Code Description 00LDA Load from … 0110 … cell 10 02OUT Output 03SUB Subtract … 0411 … cell 11 from the accumulator 05BRZ Test the accumulator; if zero, … 0609 …branch to cell 09 07BRBranch to… 0802 …cell 02 09HLTStop Processing 1099Data: Starting Value 1101Data: Counting down in 1’s

3 Trace the Program Use a program trace sheet like this to help you understand what is happening

4 Starting Position

5 00 LDA 01 10 Load the contents of RAM Cell 10 into the Accumulator

6 02 OUT Output the contents of the Accumulator

7 03 SUB 04 11 Subtract the contents of cell 11 from the Accumulator

8 05 BRZ 06 09 Test the contents of the Accumulator. If the answer is zero, branch to RAM Cell 09 Test the contents of the Accumulator. If the answer is zero, branch to RAM Cell 09 Accumulator = 98 Do nothing. Accumulator = 98 Do nothing.

9 05 BR 06 02 Branch to cell RAM Cell 02

10 02 OUT Output the contents of the Accumulator

11 03 SUB 04 11 Subtract the contents of cell 11 from the Accumulator

12 05 BRZ 06 09 Test the contents of the Accumulator. If the answer is zero, branch to RAM Cell 09 Test the contents of the Accumulator. If the answer is zero, branch to RAM Cell 09 Accumulator = 97 Do nothing. Accumulator = 97 Do nothing.

13 05 BR 06 02 Branch to cell RAM Cell 02

14 02 OUT Output the contents of the Accumulator

15 The program continues.... Now... continue the program for yourself for another two ‘jumps’ back to cell 02

16 ... to here This is the point you should now have reached.

17 ... and further continues... This is the point you should now have reached. To save a lot of tedious work, we are going to miss out a lot of iterations and go to where the numbers reach down towards zero

18 ... to here. We have now reached the point where the last number output was 2

19 03 SUB 04 11 Subtract the contents of cell 11 from the Accumulator

20 05 BRZ 06 09 Test the contents of the Accumulator. If the answer is zero, branch to RAM Cell 09 Test the contents of the Accumulator. If the answer is zero, branch to RAM Cell 09 Accumulator = 1 Do nothing. Accumulator = 1 Do nothing.

21 05 BR 06 02 Branch to cell RAM Cell 02

22 02 OUT Output the contents of the Accumulator

23 03 SUB 04 11 Subtract the contents of cell 11 from the Accumulator

24 05 BRZ 06 09 Test the contents of the Accumulator. If the answer is zero, branch to RAM Cell 09 Test the contents of the Accumulator. If the answer is zero, branch to RAM Cell 09 Accumulator = 0 Branch to Cell 09 Accumulator = 0 Branch to Cell 09

25 09 HLT Stop the Program

26 Program Flowchart Store 99 in the Accumulator Subtract 1 from the Accumulator Is the answer zero? Start Stop Output the contents of the Accumulator Yes No


Download ppt "Branching on Zero A Worked Example. Branching on Zero Countdown from 99 to 1, then stop Cell Code Description 00LDA Load from … 0110 … cell 10 02OUT Output."

Similar presentations


Ads by Google