I hope you really enjoyed writing your first assembly code.
Now we move on to the second project and this one is switch red off like the name implies there is a
switch involved.
So this is an increment over Project 1 and we would press switch one on the microcontroller board to
turn on the red LCD rather than keeping it on all the time we would have to press search one and keep
it on.
So you see we are moving in a step by step manner so you understand the foundation and because the foundations
are really relevant.
So for this we would have to learn new up codes.
So far we've looked at the move code we've looked at the load looked at store and we used it in our
program we looked at B BRL.
We've seen the big X LR And we've seen no operation.
So we would have to add more in order to use the switch in our program.
So let's look at the new ones.
So we have up code number 8 C MP This is compare and what this one does is it subtracts the value of
the second operation from the first.
Let's take a look at an example.
Let's say we have C MP our serial number one.
It compares the value of our serial with number 1.
And how does this comparison how he knows whether one is greater than the other is true subtraction
and there is that P E Q And what this one means is branch if equal to zero B Q mostly used with CMB
instruction.
So as we said the C and P compares by means of subtraction and after it's performed the subtraction
and the resource it comes up with is zero.
Then we can invoke p and q to do something else.
For example let's say we have our previous example here CMB our 0 Number 1 q l e d 1.
What this implies is if you compare our zero to the number one and it's equal branch to l eighty one
and we can think of a leading one as a subroutine somewhere.
Compare the value of our zero branch to one if resource of course zero.
Yes and we have our OB code number 10.
Wow we know 10 ACOs now.
And trust me there is a lot you can do with these of course alone.
They are the fundamentals and you have to understand them and know how to use them.
And I'm glad you do.
I hope you do.
I trust you.
We have to be an E and B and E branch.
It seemed like it's not set meaning it's not zero and you know the C flag is the Zero flag.
So if this zero flag is no set price which means you can think of this as the opposite of the P Q The
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
implies not so if you see exclamation as zero meaning not zero.
Branch if not zero.
So that's the opposite of the B.
Let's see this example.
We have delay.
Let's take this subroutine called DeLay and what DeLay Dallas's first loads.
One second one second.
You can think of as a variable into our zero and then subtracts the value one from our zero.
And I'm sure you have noticed.
Yeah we have Iris your iris you are one.
Yes.
It's like we have we have three operations in the court exam instruction set.
You can use to upfront and three operations sometimes.
In fact we can delete this our zero.
What this are zero is basically doing is that subtract one from our serial and put the value back into
our zero.
So it's like our zero equals to our zero minus one.
That's what it means here.
This so I assume B as our 0 0 1 subtract one from our as you put it back in.
And this this is a subroutine called delay and we said b an E delay b e back to the same subroutine
meaning if it's not zero come back here so you can see this is some sort of account Dow you have and
finally one second and one second could be as large as let's say the number six million.
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
if not equal to zero.
Yes I'm glad you understand remember sea flag is the Zero flag.
It a set one sea course to zero and not set when sea is in the number.
So when we saw cracked in any other number it would continue doing it on to sea.
Of course zero does elegant.
Let's see.
Number eleven up no.
By 11:00 we have the as UBS the subs we just looked at it subtracts and sets flag in a P S.
Ah yes that's an interesting one.
We could use issue B as you B as an S you b without the s.
They both mean subtract but when you have the s after this it means update or sets the flags in the
AP s are.
Remember we dealt with the AP s r and you know the AP s our flags like this zero flag that carry flag
and so on and so forth.
So if we were just doing a subtraction and we wanted the answer we didn't want to use the outcome for
something else we could have used SUV with all the s but we want to set the flag to compare with something
else wanted the outcome to be used in a comparison.
So we put the s here and what is does is it sets the the AP as our flag.
And remember the PSR.
Let's take a look at this example.
Let's say our zero.
Course I assume minus our 1 Yes we dealt with this.
Remember this one sets the flag here and there's a visual aid of the APC are.
So what this would do is it would set a zero flag and tell us or it would set the negative flag as well
depending on the outcome at every level of this.
These flags here are changed because we put this s here.
Yes the s imply set a PSR flags and you would see when we when we go into more projects you would see
we might have at plus s here meaning odd and then update the AP as our flag.
So when you see an S not on instruction it implies update the PSA which means the flags these flags
here.