 In this video, we're going to be practicing with some standard conditional statements. In comparison in the next video, we'll look at how we could represent case statements. Some people prefer to use the case style even for regular if and if else statements, but we'll start with the basic presentation and then show the case style in the next segment. So I've got a series of if and else if statements that I'd like to implement in assembly language and just to speed things up, I've already added the strings that I'm going to be printing out in each of the various cases. So in the first case, I just want to test to see if contents of t0 are equal to the contents of t1. If they are, then I'm going to print out hello. If not, I'll just print out world. So I'm going to actually set up my conditional statement sort of backwards. I'm going to say that if t0 is not equal to t1, then I will go to the print world label. There's the print world label now. If t0 is not equal to t1, I will skip this part where I would print hello out. This can seem a little backwards at first, but it gets easier after some practice. So now I know that t0 must be equal to t1 if I've reached the line after the branch. So now I can print the hello string out. After I've printed hello, I would exit the if block and then I'm always going to print world. In this case, I have to be sure that I am sticking 4 into v0 in both cases, because I may not actually run this instruction up here where I put 4 into v0. So this is not necessarily a duplicate. In order to test this, I'll need to put a couple of values into t0 and t1. So I'll start by just putting 0 into t0 and t1. Now I can come over here and run my code and it prints out hello world because t0 is equal to t1. I'll go ahead and change the value of t1 to be 1 now. Then when I run this code, it just prints out world because it failed the if test. So this time, t0 was not equal to t1, so it just branched down to the print world label and skipped the code where it would have printed out hello. I'll do a similar thing down here. This time, I only want to print out hello if t0 was not equal to t1. So as before, I'm going to make a branch that skips over the if block if my condition is actually false. So if t0 equals t1, then I will go to my nf label, which I'll put down here after my if block. So inside my if block, I'm just going to print out hello again. So I'll actually come grab this code and paste it right into the block. After I've implemented my if block, I still need to print out the word world regardless of whether or not t0 was equal to t1. So again, I'll just grab this code that prints out world for me and we'll go run this code. For the first test, we still saw that t0 was not equal to t1, so it only printed out the word world. For the second one, we've got the opposite condition. In this case, t0 is not equal to t1, so we print out hello and then print out world. So here we have hello world. If I go change t1 back to zero and run my code, then it prints out the opposite. The first case, I get hello world, and in the second case, I just get world. But we can make this a little more complicated. This time I'm going to look at what will happen when we have a relationship for our condition. Now we're not just looking to see if t0 is equal to t1 or not. We're looking to see if t0 is less than t1 or not. And this time we're also going to have an else condition. So as before, I'm going to start off by writing a branch statement that will test to see if my condition is false. So I'm going to branch if t0 is greater than or equal to t1. And I'll go down to my else block in that case. But if t0 is less than t1, then it will fail this test and fall through to the next line of code. Here I'm just going to print out my if string. By this point, I know that I have the value four in v0. So I'm not going to bother loading it back in anymore. I've had two instructions that I know load four into v0. So I know it's just going to stay there. None of my other instructions are going to overwrite that value anytime soon. So now I've implemented my if block. Next I need my else. So there's a couple things I need to do here. What is that I want my else label? You can see the else label matches up with the else label that I used in the branch. The other is that I only want to run this block of code if my condition was false to begin with. I don't want to run it if my condition was true and false. So I'm going to jump over all of this code in my else block to an end else label. I'll put that down here. There's no real requirements for what I name my labels as long as I'm not duplicating any of them. So I couldn't have named this one end if because I'd already used it up here. Inside my else block, I'm just going to print out the string else. And I'll go back and fix my load address instruction. But now this is it. This is enough to print out the else string. And then afterwards, my code will just keep running. Regardless of whether I took the if block or the else block, it will get down here to the end else label, and it will just keep running the next line of code. So for the moment, t0 is equal to t1. So we should expect to end up in the else block. Unfortunately, I used the else label twice. So qtspim complained. But once I rename one of those two else labels, it's happy and it runs. And you can see that yes, we ended up in the else block. So this time t0 is less than t1. So when I run the code, it tells me I ended up in the if block. I swap those back around, then t0 is greater than t1. And I end up in the else block again. For our next case, we're going to test to see if t0 is less than or equal to t1. So as before, I'm going to set this up to test for when the condition is false. So now when t0 is greater than t1, that is the only time where this condition would be false. So in that case, we'll go to the else three label that I'll put down here. Otherwise, t0 is less than or equal to t1. So we'd fall through and start running the if block. If block just says to print out the if two string, again, I don't want to run my else block. So I'm going to jump over that section to an end else two label. I'll add that down here after my else three block. Now in here, I just need to print out the else two string. And that's it. So t0 is currently one and t1 is zero. So t0 is greater than t1. So we should expect to end up in the else two condition. So yes, we see we got else two again, changing t0 to zero. Now we get the if two condition, because t0 was in fact equal to t1. When I make t1 larger than t0, we should also expect to end up in the if two condition. And we do it. The last two cases we'll look at greater and greater than or equal to. We'll be doing the same sort of thing. When t0 is not greater than t1, then it's less than or equal to t1. And I'll go to an else four label. My if block says to print out this greater string. And then I'll exit my if case. In my else case, I print out the not greater string. Then I'd have my end else three label to indicate that I'm done with this if else block. For the last case, we have a greater than or equal condition. So I'll be looking for the case where t0 is less than t1. This case ends up working rather similarly to the previous ones. All we've really done is changed the condition, because that's all that's really changing in each of these cases. We have a different condition controlling whether we enter the if block or the else block. But otherwise we're just printing out a string. Now I've got t0 equal to zero, t1 equal to one. So t0 is less than t1. So I would expect to end up in the not greater case, as well as the not greater or equal case. So I get both of those out. When I change t1 to be zero, then I get that t0 is not greater than t1. But t0 is greater than or equal to t1. And then lastly, I'll test this code when t0 is one and t1 is zero. So in this case, they both came back saying that t0 was greater than t1. So those are our six basic conditional statements. Using one of these branch conditional instructions or pseudo instructions is sufficient to allow you to implement a simple if statement or an if else block.