CS/COE 447: Home Exercises (you do not need to hand anything in) ================================================================= Getting started in MIPS assembly language Download Mars.jar from the course website. On a windows machine, you just need to click on Mars.jar to launch the simulator. (If you want to use Mars from the command line, you'll need to see the instructions in the help menu.) Click on the Edit tab on the top left (in this pane, you'll see your assembly language program. Well, after you've created it). Go to File and click on New, to start a new program. Let's start with a simple program. Start the program with: .text This says that the following are program instructions (and not, e.g., data). Let's do the following: $t4 = 3 + 5 + 8 First, let's put 3 in $t4: addi $t4,$zero,3 This says to take what is stored in register $zero, add 3 to it, and put the result in register $t4. $zero ALWAYS contains 0, so this puts 0 + 3 into register $t4 You can check yourself at this point! But before you can go further, MIPS needs you to save the file. (Call the file first.asm) Now, go to the Run tab and click on assemble. The Text segment shows you: Address -- where this instruction is stored in memory Code -- the machine code of the instruction Basic -- [not too helpful at this point] Source -- the original instruction you typed in The Data Segment in the middle of the page shows you the contents of the part of memory where data is stored. We haven't put any data in memory, so the values here are all 0. The bottom window gives messages from the simulator. Any error messages will be displayed here. Now, click on Go to execute the machine code (technically, "simulate" it). Look at $t4 in the panel on the right. It should contain 3. Ok, let's continue the program (to get back to your program, just click on Edit) now we want to add 5 to our running sum: addi $t4, $t4, 5 And then we want to add 8: addi $t4, $t4, 8 Assemble the program again, and run it. You will see that $t4 contains 0x00000010 The 0x just means that the number following it is in hex. 8 + 5 + 3 = 16 in decimal 16 decimal = 10 hexidecimal. Try one more thing: Assemble the program again (you need to assemble it again to be able to run it again) Click Step under Run (or the triangle with the 1). This will step through your instructions one by one. As each instruction executes, you will see registers and memory being updated. So, after the first instruction, $t4 contains 0x00000003; after the second it contains 0x00000008; after the third, it contains 0x00000010. This shows a good way to learn the assembly language. Enter and assemble instructions; this will show you the machine code that is produced. Then, step through executation so you can see the effects of the individual instructions.