 This time we're going to write a program that can just print out some text for us. I will start with the data directive, and this tells the assembler that I'm going to give it some data to work with. This could be some array data, or in our case some strings, but the assembler will just take all of this data and put it into memory for us. This will allow us to access it later in our program. So now I can enter my string. I will start with a string that I will name 1, and it's a string. So I'm going to use the .asciz directive, which will tell the assembler that I'm going to give it a string, and I would like it to be null terminated. So it will have a 0 at the end. So now I have a string. Since I'm interested in printing this out, I'm next going to come up with some code to allow me to actually print this string. The .text directive tells the assembler to expect some code now. I begin with the main label so that QTSpim knows where I'd like to start my code at. I might not actually want to start my code at line 1. I might want to start it partway down in my program. In this case, I do want to start at the top, so that's the first piece of code that I'm putting in. To print a string, I need to put the value 4 into register v0, and then I need to put the address of my string into a0. Then I can use the syscall instruction to tell the operating system to actually go print this string out. 4 is the syscall operation to print a string, so I put the 4 in v0. And then the operating system will expect a pointer to a string in register a0. So I use the load address sudo instruction to tell the assembler to remember where it put this string in memory, and then copy that value into a0. That way I'll be able to access it. So then when I run my system call operation, it will be able to print out string 1. Since this is all I want to do with my program, I will next add in a system call to quit the program. So that just means putting 10 into v0 and then making another operating system call. So if I go over to QTSpim and I run this program, it prints out this is string 1. Not terribly exciting, but that's all we wanted it to do for now. But if I want it to print a second string, string 2, I can put 2 into a0 and then make another system call. This time I won't have to set the value of v0 ahead of time, because it won't have changed from the first time that I set v0. In assembly language, the value of our registers isn't going to change unless we perform an operation that actually changes them. In this case, the system call isn't going to modify v0, so I have no problem just printing out multiple strings by referring to a new string and just making another system call. I do have to go back and actually add the string to memory though. Now if I run this new code, I see it does print out this is string 1, this is string 2, but that's a little hard to read. So I can use some of the formatting characters that we're used to like backslash n to add a new line, backslash t to add some tabs. Now I have some formatting for my text as well, but I don't have to put all of my data at the top of my program. I can put my data wherever I find it useful. So if I want to add another string here in the middle of my program, I can do this. So now it prints out hello world as well as everything else I had before. When the assembler gets this code, it will go through and pull out all of those data sections. All of the data goes into data memory, all of the code goes into the text memory, and the assembler will remember where all of that data is going to. All of the lines of code will show up in the same order that they do in my source code, but they don't have all of the data interleaving them. So the data shows up over in the user data segment instead. So printing out text requires a few instructions, but it's actually not too complicated. As long as you know where your string is, you can use system call number four to just print out another string.