 In this video, I'm going to be introducing QTSpim. So this is the main interface for QTSpim, as you'll see it when you first open the program. There's two primary windows here. This one on the right shows you your code. At the moment, I've just started the program. So the only thing in there is some default user code that is just designed to run our program and then quit afterwards. And some of the operating system. So you can see everything down here is operating system code and we're really not going to worry about that. The left-hand side are the contents of our registers. So we have all of the registers that we're familiar with from register zero all the way up to our return address. We also have a couple of others like our program counter, our exception program counter, and other things related to having exceptions. First thing you'd probably like to be able to do with QTSpim is to just run a program. So I'm going to use this, re-initialize and load button here. And I'm going to select a program to run. So you can see it's updated my code in here. It's added all of that code that I had from my source code file into the simulator. Now we have a series of buttons up here that allow us to control how our program actually runs. This is a really simple program so I'm just going to click the play button. So it ran through, it printed out a bunch of text for me in my console just the way you would expect. Now if I want to run through that again, I can click this button which just clears all the registers. So it still has my code in there but it's reset the registers as though my program hasn't run. So if I click the play button again, it prints out another set of that text as though it just ran the program a second time. But if I'm interested in debugging my code, I might not want to just run through all of the code all at once because somewhere in there something goes wrong and I'd like to see what's happening. So instead I can use this single step button up here. If I click on that then the simulator is going to walk through this code one line at a time. And you can see now that the registers on the left change as I walk through my code. So I just put a four into V zero. So you can see that V zero now has the value of four. Next I'm going to load in the address of a string. So you can see that value is now in A zero. Next instruction is the syscall. So when I run that, you can see it prints out the string. The next instruction loads the address of another string into A zero. Then it asks the simulator to print that string as well. By default, this window shows me my code but I also have another option. I can ask it to show me all of the data in my system. In this case, I've clicked on the data tab and you can now see two things. One is that all of those strings are over here in memory. This is where they physically reside in our system's memory. They all have addresses associated with them and I could actually go through and find where each string starts and stops and use those addresses in my program instead. You can also see that I have a user stack over here. The moment it's got two parts to it. One is stuff that might potentially relate to my program. Everything else below that is probably not going to be useful for us. In this case, it includes things like my operating system path and several other related parameters that my Windows operating system is interested in. Those are probably not going to be relevant to running programs on QtSpim but the upper part of that user stack will be interesting when we start having functions, we start putting things on our stack. We'll be able to see exactly what is on there, where it is and how that's actually changing. The QtSpim simulator implements both the main integer processor as well as the floating point and exception coprocessors. So I also have the option of looking at the floating point registers instead of the integer registers. We can see them both as single precision registers or as double precision registers, depending on how you've written your code and what kind of processing you're interested in doing. Next, I'll load in some slightly more interesting code. If I run it, this code will calculate the area and perimeter of a rectangle as well as a triangle with those two values. Again, this code just works, but if we decided that there was some problem in here, I might be interested in seeing what's going on and why it's wrong, what do I need to do to fix it? So I could just step through my entire set of code one line at a time. This would be effective but probably pretty slow and boring. I'm likely to miss something important while I'm stepping through one line of code at a time but instead I might have some idea where my bugs are. In that case, I could set a break point. So I think it's likely that if I have a bug, it's related to the arithmetic here. So I'm going to right click on this first line of code where I'm doing arithmetic, which is the add instruction. And I'm going to click set break point. So now there's a small break point icon next to that line of code. When I run my code, it will run as normal until it gets to that line of code. Then it pauses the code so I could look at my registers. I can see if something looks unusual or unexpected over there or I can just start walking through my code one line at a time. So now I can see how it operates, how the registers are changing, but I didn't have to start at the beginning. I was able to set a break point so that my code ran normally until it gets to that point. And then I can step through the code and see what it's doing and why it might be going wrong. Once I'm done with this break point, I can right click on that line of code again and select clear break point. And now you can see the icon has gone away. This time I can run the code and it just goes right past that line of code. The break point is gone, so the code runs as normal. One problem people often have is that they'll click the X to close their console and then the next time they try to run their code, the console doesn't come back up. If you have this problem, you can click on window and select console and you can see that console is there. It's still working as normal. While QTSpim does have a handful of options that are interesting to look at, one of the more useful ones is just how do we display the contents of our registers and our data memory? By default, all of these values are displayed as hexadecimal, but we have the option of changing them. So I've just run my program again, it's quit. So v0 has the value of 10. But by default, that shows up as a and that may not be relevant. That may not be interesting to you. Here I can see that I've put five into s0 for the length of my rectangle, three into s1 as the width of my rectangle. The perimeter was 16, so that's in s2. The area is 15, which is in s3. And the area of the triangle is seven, which is in s4. But if I still have those values in hexadecimal, it's not as obvious that 10 corresponds to the perimeter, f corresponds to the area of a rectangle. So if you're interested in seeing what the values are in those registers, you may want to change that option to decimal. If you're interested in looking at addresses, you'd probably like to leave it as hexadecimal instead. And you have the same options with data memory. You can choose to represent values in binary, hexadecimal, or decimal, as is relevant to what you're trying to do at the moment. So for a couple of last reminders, majority of the controls are up here in the toolbar. We can just load a file, but that's usually not interesting. It's usually much more useful to reinitialize the simulator and then load our code in. If you've made some changes to your code or you just want to run a different program, then that's going to make sure to clear everything out before it puts something new in. We have a reset button, which just resets the registers, which is usually what we want if we just want to run our program a second time. The reinitialize button is similar, but it will also clear out all of the code that we've put in there. And then we have the play, pause, stop, and single step buttons. We saw what the play and the single step buttons do. The pause button is usually not interesting because our code runs so fast that it's hard to pause it in a good place. The stop button can be useful if your code is stuck in an infinite loop, but QTSpim has the problem that it may not respond to the stop button in that case. So that's the majority of the features that QTSpim provides for us. It's not a whole lot of stuff, but it's everything we need to really be able to test our programs and debug them.