1
00:00:04,550 --> 00:00:08,690
I hope you really enjoyed writing your first assembly code.

2
00:00:08,690 --> 00:00:15,680
Now we move on to the second project and this one is switch red off like the name implies there is a

3
00:00:15,680 --> 00:00:17,030
switch involved.

4
00:00:17,030 --> 00:00:25,100
So this is an increment over Project 1 and we would press switch one on the microcontroller board to

5
00:00:25,100 --> 00:00:32,240
turn on the red LCD rather than keeping it on all the time we would have to press search one and keep

6
00:00:32,240 --> 00:00:32,720
it on.

7
00:00:32,990 --> 00:00:41,030
So you see we are moving in a step by step manner so you understand the foundation and because the foundations

8
00:00:41,270 --> 00:00:42,540
are really relevant.

9
00:00:42,560 --> 00:00:45,820
So for this we would have to learn new up codes.

10
00:00:45,860 --> 00:00:53,780
So far we've looked at the move code we've looked at the load looked at store and we used it in our

11
00:00:54,140 --> 00:00:57,040
program we looked at B BRL.

12
00:00:57,770 --> 00:01:01,630
We've seen the big X LR And we've seen no operation.

13
00:01:01,700 --> 00:01:07,130
So we would have to add more in order to use the switch in our program.

14
00:01:07,130 --> 00:01:09,120
So let's look at the new ones.

15
00:01:09,200 --> 00:01:16,370
So we have up code number 8 C MP This is compare and what this one does is it subtracts the value of

16
00:01:16,370 --> 00:01:19,100
the second operation from the first.

17
00:01:19,100 --> 00:01:21,330
Let's take a look at an example.

18
00:01:21,590 --> 00:01:25,310
Let's say we have C MP our serial number one.

19
00:01:25,310 --> 00:01:28,570
It compares the value of our serial with number 1.

20
00:01:28,610 --> 00:01:34,280
And how does this comparison how he knows whether one is greater than the other is true subtraction

21
00:01:34,760 --> 00:01:45,410
and there is that P E Q And what this one means is branch if equal to zero B Q mostly used with CMB

22
00:01:45,410 --> 00:01:46,130
instruction.

23
00:01:46,310 --> 00:01:54,050
So as we said the C and P compares by means of subtraction and after it's performed the subtraction

24
00:01:54,170 --> 00:01:57,460
and the resource it comes up with is zero.

25
00:01:57,500 --> 00:02:00,780
Then we can invoke p and q to do something else.

26
00:02:00,800 --> 00:02:08,330
For example let's say we have our previous example here CMB our 0 Number 1 q l e d 1.

27
00:02:08,390 --> 00:02:15,930
What this implies is if you compare our zero to the number one and it's equal branch to l eighty one

28
00:02:16,040 --> 00:02:19,880
and we can think of a leading one as a subroutine somewhere.

29
00:02:19,920 --> 00:02:24,450
Compare the value of our zero branch to one if resource of course zero.

30
00:02:24,470 --> 00:02:28,710
Yes and we have our OB code number 10.

31
00:02:28,730 --> 00:02:30,750
Wow we know 10 ACOs now.

32
00:02:30,770 --> 00:02:34,710
And trust me there is a lot you can do with these of course alone.

33
00:02:34,720 --> 00:02:40,460
They are the fundamentals and you have to understand them and know how to use them.

34
00:02:40,490 --> 00:02:42,290
And I'm glad you do.

35
00:02:42,350 --> 00:02:43,440
I hope you do.

36
00:02:43,490 --> 00:02:44,810
I trust you.

37
00:02:44,810 --> 00:02:48,790
We have to be an E and B and E branch.

38
00:02:48,890 --> 00:02:57,480
It seemed like it's not set meaning it's not zero and you know the C flag is the Zero flag.

39
00:02:57,500 --> 00:03:05,700
So if this zero flag is no set price which means you can think of this as the opposite of the P Q The

40
00:03:05,780 --> 00:03:16,070
BQ said branch if it's equal to zero and a B and E says branch it's not zero exclamation a sign in programming

41
00:03:16,130 --> 00:03:20,900
implies not so if you see exclamation as zero meaning not zero.

42
00:03:20,890 --> 00:03:22,580
Branch if not zero.

43
00:03:22,790 --> 00:03:24,290
So that's the opposite of the B.

44
00:03:24,480 --> 00:03:26,100
Let's see this example.

45
00:03:26,480 --> 00:03:27,530
We have delay.

46
00:03:27,540 --> 00:03:33,230
Let's take this subroutine called DeLay and what DeLay Dallas's first loads.

47
00:03:33,350 --> 00:03:35,450
One second one second.

48
00:03:35,450 --> 00:03:43,490
You can think of as a variable into our zero and then subtracts the value one from our zero.

49
00:03:43,710 --> 00:03:46,100
And I'm sure you have noticed.

50
00:03:46,370 --> 00:03:48,760
Yeah we have Iris your iris you are one.

51
00:03:48,950 --> 00:03:49,670
Yes.

52
00:03:49,940 --> 00:03:57,430
It's like we have we have three operations in the court exam instruction set.

53
00:03:57,560 --> 00:04:01,790
You can use to upfront and three operations sometimes.

54
00:04:01,790 --> 00:04:05,330
In fact we can delete this our zero.

55
00:04:05,330 --> 00:04:13,070
What this are zero is basically doing is that subtract one from our serial and put the value back into

56
00:04:13,070 --> 00:04:14,240
our zero.

57
00:04:14,270 --> 00:04:18,590
So it's like our zero equals to our zero minus one.

58
00:04:18,620 --> 00:04:19,990
That's what it means here.

59
00:04:20,000 --> 00:04:26,830
This so I assume B as our 0 0 1 subtract one from our as you put it back in.

60
00:04:26,960 --> 00:04:34,670
And this this is a subroutine called delay and we said b an E delay b e back to the same subroutine

61
00:04:35,330 --> 00:04:43,460
meaning if it's not zero come back here so you can see this is some sort of account Dow you have and

62
00:04:43,460 --> 00:04:50,660
finally one second and one second could be as large as let's say the number six million.

63
00:04:50,720 --> 00:04:59,840
Keep in mind B E S the opposite of the B Q branch if it's equal to zero that's P Q and B and E primes

64
00:04:59,930 --> 00:05:01,450
if not equal to zero.

65
00:05:01,460 --> 00:05:06,550
Yes I'm glad you understand remember sea flag is the Zero flag.

66
00:05:06,550 --> 00:05:12,140
It a set one sea course to zero and not set when sea is in the number.

67
00:05:12,880 --> 00:05:18,280
So when we saw cracked in any other number it would continue doing it on to sea.

68
00:05:18,280 --> 00:05:21,080
Of course zero does elegant.

69
00:05:21,160 --> 00:05:21,710
Let's see.

70
00:05:21,710 --> 00:05:23,320
Number eleven up no.

71
00:05:23,380 --> 00:05:31,080
By 11:00 we have the as UBS the subs we just looked at it subtracts and sets flag in a P S.

72
00:05:31,130 --> 00:05:33,680
Ah yes that's an interesting one.

73
00:05:33,760 --> 00:05:39,680
We could use issue B as you B as an S you b without the s.

74
00:05:39,910 --> 00:05:49,600
They both mean subtract but when you have the s after this it means update or sets the flags in the

75
00:05:50,110 --> 00:05:51,400
AP s are.

76
00:05:51,460 --> 00:05:59,640
Remember we dealt with the AP s r and you know the AP s our flags like this zero flag that carry flag

77
00:05:59,800 --> 00:06:01,180
and so on and so forth.

78
00:06:01,810 --> 00:06:07,780
So if we were just doing a subtraction and we wanted the answer we didn't want to use the outcome for

79
00:06:07,780 --> 00:06:14,650
something else we could have used SUV with all the s but we want to set the flag to compare with something

80
00:06:14,650 --> 00:06:18,660
else wanted the outcome to be used in a comparison.

81
00:06:18,790 --> 00:06:26,170
So we put the s here and what is does is it sets the the AP as our flag.

82
00:06:26,170 --> 00:06:28,420
And remember the PSR.

83
00:06:28,420 --> 00:06:30,460
Let's take a look at this example.

84
00:06:30,770 --> 00:06:31,840
Let's say our zero.

85
00:06:31,870 --> 00:06:35,620
Course I assume minus our 1 Yes we dealt with this.

86
00:06:35,620 --> 00:06:42,680
Remember this one sets the flag here and there's a visual aid of the APC are.

87
00:06:42,700 --> 00:06:49,420
So what this would do is it would set a zero flag and tell us or it would set the negative flag as well

88
00:06:49,450 --> 00:06:52,820
depending on the outcome at every level of this.

89
00:06:53,050 --> 00:06:56,960
These flags here are changed because we put this s here.

90
00:06:56,980 --> 00:07:06,550
Yes the s imply set a PSR flags and you would see when we when we go into more projects you would see

91
00:07:06,550 --> 00:07:14,940
we might have at plus s here meaning odd and then update the AP as our flag.

92
00:07:14,950 --> 00:07:23,500
So when you see an S not on instruction it implies update the PSA which means the flags these flags

93
00:07:23,500 --> 00:07:23,800
here.
