Hello and welcome back.
In this lesson, we are going to do a multiple if test.
A multiple if test looks like this.
There's an if statement, and then inside it there will be two tests.
You are testing whether A is larger than B and also whether B is larger than C.
If these two conditions are true, then you will assign four to A.
Then you end it.
So in order to implement this in assembly, we can break it down like this.
So we will test whether A is larger than B.
If A is not larger than B, then we don't have to test whether B is larger than C.
So this is how we do it.
First, we move the variable A value into -.
Then we move the variable B's value into -.
Then we move C's value into -.
And then we compare - and -.
If - is less than or equal to -, then this condition is false, so it will jump
to the endif. That means it will not continue with the second test.
However, if A is larger than B, then it will continue with the comparison between - and -.
And then if - is larger than C, then the condition will be false, and it will go on to assign four
to the variable A.
However, if - is not larger than -, then it will jump to the endif over here and it will quit.
So the first thing we need to do is to find the addresses that we are going to use for variables A,
B, C, and also the address in the text section that we are going to use for endif.
So to do that, let us first go to the dump here.
Click on it to select it.
Then you click on memory map, go to the BSS segment, right-click Follow in dump.
Scroll down and look for a location which is empty.
Maybe over here. Right-click on this.
Copy this address.
This will be variable A.
Then we paste it there.
We are going to assign three to that variable.
So come back to this address, right-click, binary edit, and key 03.
Next, we look for an address for variable B.
So maybe this one will do.
Right-click, copy address, and then paste it in here.
And we assign two to this variable.
So let's come back here and right-click, select binary edit, and key in 02.
Next, we look for an address for variable C.
Maybe this one.
Right-click, copy address, and paste it in here.
And we are going to assign one to this address.
So come back here, right-click, binary edit, and key in 01.
So now we have got our three variables.
And we have also initialized them with the values three, two, and one.
Next, we need to look for the address for the endif that we are going to use in the text segment.
So the text segment, we scroll down to the bottom and maybe pick this one.
Right-click the address.
Copy the address.
And paste it in here.
Now we have all our addresses.
We can start coding.
So let's go and code all this over here.
Put the breakpoint there and then start keying in your code.
MOV -.
And then copy your address for variable A.
And paste it in here.
Next will be MOV -.
Copy the address for variable B.
And paste it here.
Next will be to move -.
Copy the address for C.
And paste it here.
Next will be the compare - with -.
Followed by jump less or equal to.
Then we copy the address of endif.
And paste it in here.
Next, we will compare - with -.
And then we'll do jump less or equal to
endif.
Copy the address for endif from here.
And paste it in here.
Finally, we will move four to variable A.
Copy the address of variable A.
And paste it in here.
Type four.
Now we need to check, make sure we have entered correctly.
So let's check.
This is -, 0x407000, which is variable A, 0x407000.
Next one is -, 0x407020, which is variable B.
Next is -, which is 0x407100.
Next is compare - with -.
Next is jump
to jump less or equal to endif.
Endif would be this address, 0x4015B9.
Next would be compare - with -, then jump less or equal to endif again, which is 0x4015B9, and
finally move four to variable A.
So variable A is 0x407000.
So now we can run to our breakpoint.
Step over, it moves variable A to -. Variable A is three, so it's three now.
Then it moves variable B, which is two, into -.
Next, it moves variable C, which is one, into -.
So we have three, two, one.
Next, we compare variable A and B.
We compare register A and B, which is three and two.
So it's bigger than two.
So yes, it is, so it will not jump.
As you can see, the arrow is grayed out and jump is not taken.
So we step over.
We go to the next line.
We compare - with -. - is two, bigger than one?
So we step over.
Yes, it is bigger than one.
So this jump will not jump.
As you can see again, the arrow is grayed out and jump is not taken.
It's shown here.
So it's going to go straight and assign four to variable A.
So let's step over.
And you see now four has been assigned to variable A.
So this is how you can implement multiple if tests inside assembly language.
Thank you for watching.