1
00:00:02,630 --> 00:00:07,980
In this lesson we're going to look at how the compiler acts on conditions.

2
00:00:08,000 --> 00:00:12,290
Let's go over what we said about the P.C. in the previous lesson.

3
00:00:12,290 --> 00:00:18,770
As you remember we said a piece these times for the program counter and that it stores the address of

4
00:00:18,770 --> 00:00:21,610
the next instruction to be executed.

5
00:00:21,950 --> 00:00:25,280
Yeah we are going to look at how that happens.

6
00:00:25,280 --> 00:00:31,600
Also remember our previous program worked in an incremental linear waterfall manner.

7
00:00:31,640 --> 00:00:40,010
Here we are going to implement conditions and see what branch and happiness in the disassembly view

8
00:00:40,190 --> 00:00:42,640
and see how the compiler works with that show.

9
00:00:42,710 --> 00:00:48,630
We're going to start by modifying our current code which looks like this currently.

10
00:00:48,920 --> 00:00:55,400
Remember we started by just increment and with our decrement and just with a plus plus contour and here

11
00:00:55,850 --> 00:00:57,550
we have eight of them.

12
00:00:57,590 --> 00:01:03,400
Meaning we add in one to counter eight times if it comes eight.

13
00:01:03,440 --> 00:01:05,440
After that as it's implied.

14
00:01:05,510 --> 00:01:12,410
So instead of typing this out eight times let's just put it in a loop and see how the compiler would

15
00:01:12,410 --> 00:01:15,280
deal with this loop although the results would be the same.

16
00:01:15,320 --> 00:01:22,100
Let's observe in the disassembly view how the compiler works with that we can start by just wiping all

17
00:01:22,100 --> 00:01:23,340
of this off.

18
00:01:23,360 --> 00:01:31,940
This is eight of them and we could just use a while loop like we have here and see while the counter

19
00:01:32,600 --> 00:01:38,930
is less than eight and then we can put what we want which is plus plus counter

20
00:01:42,610 --> 00:01:46,650
so this should give us the same resource and let's see.

21
00:01:47,560 --> 00:01:55,550
So let's just exit the debugger and run this code by compiling it first and then back to the debug view.

22
00:01:56,090 --> 00:01:57,020
Okay.

23
00:01:57,220 --> 00:02:06,310
So let's step in and see first of all let's just check whether the Locos view gives us the value eight

24
00:02:06,370 --> 00:02:07,640
at the end.

25
00:02:07,740 --> 00:02:08,680
OK.

26
00:02:08,860 --> 00:02:09,760
It doesn't give us eight.

27
00:02:09,760 --> 00:02:11,790
It ends at seven.

28
00:02:11,800 --> 00:02:17,000
This is because as it says here not in scope the variable is out of scope.

29
00:02:17,020 --> 00:02:23,220
We can just cut this from here and put it here and then it should be scope.

30
00:02:23,220 --> 00:02:30,320
Now let's exit this and then come back and then go back to debug.

31
00:02:30,660 --> 00:02:31,530
Okay.

32
00:02:31,580 --> 00:02:37,150
Now let's try this step.

33
00:02:37,370 --> 00:02:44,140
See now we have the value eight which means it gives us the same resource over here.

34
00:02:44,160 --> 00:02:44,900
You can see that.

35
00:02:45,230 --> 00:02:47,650
Let's change it to decimal form here.

36
00:02:47,670 --> 00:02:49,220
We have eight here.

37
00:02:49,260 --> 00:02:56,830
Now let's go back to the top and see how it works its way to the answer eight in the disassembly view.

38
00:02:57,060 --> 00:03:02,540
So let's observe what goes on in the disassembly view.

39
00:03:02,820 --> 00:03:09,210
First of all we need to get it I wrote back to the beginning of the main function and we have to do

40
00:03:09,210 --> 00:03:15,660
that by exiting the debugger and coming back and I will explain why we have to do that in a second.

41
00:03:16,290 --> 00:03:19,630
Let's exit with this button here and then click the same button.

42
00:03:20,070 --> 00:03:21,930
Okay to come in here.

43
00:03:22,740 --> 00:03:25,440
So as we can see currently it's pointing here.

44
00:03:25,440 --> 00:03:28,070
This the instruction that's going to be executed.

45
00:03:28,080 --> 00:03:29,320
We already dealt with this.

46
00:03:29,800 --> 00:03:31,230
So we're going to step.

47
00:03:31,230 --> 00:03:33,920
Line by line and see what goes on into disassembly.

48
00:03:33,930 --> 00:03:36,350
You would click to step with step.

49
00:03:36,360 --> 00:03:37,410
It's executed here.

50
00:03:37,410 --> 00:03:44,210
The next instruction to be executed will be to branch into this while fun this while loop.

51
00:03:44,340 --> 00:03:47,550
Remember this phase while loop is the program's loop.

52
00:03:47,550 --> 00:03:51,150
This is what keeps the program running all the time.

53
00:03:51,210 --> 00:03:55,290
In fact the while loop we are interested in is the second one here.

54
00:03:55,290 --> 00:04:01,650
That's the one that keeps adding the value one to the variable counter the next instruction will be

55
00:04:01,650 --> 00:04:07,020
to branch to this while loop and the B here stands for branch.

56
00:04:07,020 --> 00:04:10,460
And then this address is where the wire loop is.

57
00:04:10,830 --> 00:04:18,300
So let's step in now with enter the programs while loop the next instruction will be to branch into

58
00:04:18,300 --> 00:04:20,780
the while loop of our variable counter.

59
00:04:21,090 --> 00:04:22,500
So let's go.

60
00:04:22,500 --> 00:04:23,090
Yes.

61
00:04:23,100 --> 00:04:29,600
Now we are in our while loop and we can see so far counter is there was 0 0.

62
00:04:29,640 --> 00:04:33,320
We are here because we've executed this already counts here.

63
00:04:33,360 --> 00:04:39,160
In fact like we did previously this just changed it to a decimal so few.

64
00:04:39,240 --> 00:04:42,600
So let's step again which step counter is 1.

65
00:04:42,820 --> 00:04:50,410
What happened was like we had in the previous lesson RS zero of course are zero plus one does Holcomb

66
00:04:50,820 --> 00:04:52,510
counter became one.

67
00:04:52,770 --> 00:04:57,980
Remember in the previous lesson anytime we stepped we had our share of plus one.

68
00:04:57,990 --> 00:05:03,600
So after you had kept incrementing mean in the first one gave us one the second one gave us to the third

69
00:05:03,600 --> 00:05:04,910
one gave us three.

70
00:05:05,070 --> 00:05:06,680
That's what went on.

71
00:05:07,020 --> 00:05:11,280
It was always our zero answer a one after you answer one.

72
00:05:11,310 --> 00:05:12,960
Now let's take a look at this one here.

73
00:05:12,990 --> 00:05:21,800
Let's step and see rotted and having eight different add s up codes to perform the additions over here

74
00:05:21,800 --> 00:05:29,770
we have just one at s up code and this one address code works in conjunction with a C and P and b L2

75
00:05:29,780 --> 00:05:37,280
up codes to perform all the eight additions when we increment the value is first added as we see here.

76
00:05:37,340 --> 00:05:43,670
And then to see MP which is to compare instruction this new forward and how the campaign structure works

77
00:05:43,740 --> 00:05:49,700
is that it uses the means of subtraction to make its decision as we see here.

78
00:05:49,700 --> 00:05:55,970
Counter has the value to and over here our loop says the counter should keep increasing as long as the

79
00:05:55,970 --> 00:05:57,870
value is less than eight.

80
00:05:58,010 --> 00:05:59,760
So what compares to acids.

81
00:05:59,780 --> 00:06:03,440
It takes two and then minus eight.

82
00:06:04,160 --> 00:06:11,630
And at this point the answer compare gets it's minus six because two minus eight is a negative six.

83
00:06:11,630 --> 00:06:18,520
And when this happens the AP S.R. register we spoke about it's updated.

84
00:06:18,530 --> 00:06:25,800
Remember we said the AP is our house the N C C and C bit the N stand for the negative bit dizzy for

85
00:06:25,800 --> 00:06:30,840
the zero bit C for Curry bit and V for overflow bit.

86
00:06:31,160 --> 00:06:39,170
So the negative bit of the AP s our register is updated because the results from the C MP is a negative

87
00:06:39,170 --> 00:06:39,650
number.

88
00:06:40,460 --> 00:06:49,510
So after that branch which is BLT this BLT here you see is a variant of the branch instruction.

89
00:06:49,700 --> 00:06:56,960
This BLT is moving forward and the way this P L 2 works is that it goes to the AP s register and it

90
00:06:56,960 --> 00:07:04,100
checks the various bits and it makes its decision based on that and what happens is when in the AP s

91
00:07:04,100 --> 00:07:12,800
I register D The and it is set or enabled the BLT modifies the P.C. the program counter to branch to

92
00:07:12,860 --> 00:07:19,700
a different location rather than allowing the P.C. to work in its own orderly manner.

93
00:07:19,700 --> 00:07:24,070
And as we said the result of this C MP modified the end bit.

94
00:07:24,170 --> 00:07:31,780
Therefore this keeps happening until we hit the number eight and when we hit the number eight will return

95
00:07:31,790 --> 00:07:33,520
to the beginning of the loop.
