Professional Documents
Culture Documents
15, 2002
Type in the following program using a text editor (not a word processing package!) and execute it using PCSpim. PAY ATTENTION TO THE SPACES IN THE ASCII DIRECTIVES! There is a bug in PCSpim: you have to leave a blank line at the end of the program. To become familiar with the simulator it is useful to go through the following sequence of steps. FIRST download simulator and run through the on-line tutorials in the NEXT Section of the notes labeled PCSpim Tutorial Load the program into SPIM. If you typed it in correctly it should load with no errors. If there are typographical errors then a dialog window will pop up with the line number. Other wise open the Console window and you can check the error message. Continue to edit/load until all errors are taken care of. Run the program. Answer the questions in Problem #1 and see the results. The program should run with no problem. Look in the data segment. It will be filled with values starting at address 0x10010000. These values are product of the data directives in the program. Check the text segment. You will see instructions at each successive address in the text segment. Learn to associate addresses with instructions. Open the registers window and you will see the contents of all 32 registers. Check the registers contents before and after running the program. Answer the following questions After loading the sample program on following page into the SPIM simulator, what are the contents of the second, third, and fourth word in memory? Indicate the type of computer you are using to run the SPIM simulator, and after looking at the contents of the data segment, indicate if the machine uses big endian or little endian convention to store words.
1. 2.
3.
4.
How many bytes of data are being used in the data segment? At what address does the data segment begin? SPIM Sample Program
################################################################### # INSERT YOUR NAME # ECE 2030 ( E or F) # SPIM Homework#1 #################################################################### # Comments begin with the # character # Begin the data segment (declare variables) .data .asciiz SPIM is COOOOL!!! .byte 0xF2 .align 2 # enforce word alignment .word 0xF28343AA num1: .word 89 num2: .word 7 result: .word 0 result: .word 0 .text lw $t0,num1 lw $t1,num2 add $t2, $t0, $t1 sub $t3,$t0,$t1 sw $t3, result1 sw $t4, result2 # end execution of the program li $v0, 10 syscall # A bug in SPIM requires you to have an extra carriage return after the last line of code.
SIMULATOR -reload: Restarts the simulator and re-reads assembly file you have open. Use this if you run your program, make changes to it (in your editor), and want to run it again to see if the changes worked. Note that SPIM can sometimes get confused and reloading wont fix it. In these cases, close SPIM completely and restart it. -go: Starts running the program. It lets you choose what you want the program counter to start at (i.e., it lets you choose which line of code to start running at). Your program always begins at 0x00400000, the beginning of the text segment. -break: This stops the assembly program wherever it might be. You can look at what values are held in data memory, the registers, and you can see what line of code was being executed. This is useful when you are debuggingespecially if you think you are getting stuck in an infinite loop. -single step: Run next instruction only, then break. Use this to watch register and data values change as your program runs and to see which instructions are being run. You can run a single step after breaking or to start the program at the first instruction (0x00400000).
-set breakpoints: This is yet another debugging trick. Suppose you are suspicious of a certain section of your program, and want to watch it run. Open your assembly file and look at the text segment. Find the instructions you want to watch in the text segment. Click on Simulator then Set Breakpoints and enter the address of the instruction that begins the portion of code you want to watch. Now when you run your program SPIM will automatically break for you when it reaches that section of code. WINDOW -messages: This shows SPIM feedback, such as syntax errors when you load your program.
-text segment: This contains the program that is stored on the MIPS machine. The columns in this window are the following: the address of the instruction, the binary for the machine code of this instruction, the actual instruction being used, and finally the line from your assembly file that you typed in to create this instruction. -data segment: This shows the memory locations you allocated in the .data section of your program This window shows four words of data per row. -registers: LO registers. -console: Shows the contents of the 32 general purpose registers, the PC, and the multiply HI and This is the screen that you can print to and read from in your program.
-clear console: Remove the text currently on the console. Debugging Example Type in a sample program. Load the program. Run the program. Look at the text segment. Convince yourself that you recognize the instructions from your original assembly file in the Text Segment window. Set a breakpoint. Suppose you want to make sure that the SUB instruction is working correctly. Find the instruction just before the SUB in the Text Segment window. For this program, the address of that instruction is a MOVE instruction at 0x00400030. Add a breakpoint at this address (click on Simulator, Breakpoints, type in the address, click on Add, then click on Close). Run the program normally. The program will break just before the SUB instruction executestell SPIM not to continue execution. You can watch the values in the Registers window to make sure the values are correct (watch $t0, $t1, and $t2). Press F10 (Single Step) to run the program one instruction at a time. Once youre sure the program is working, press F5 (Run) to complete the program.