The objective of this lab is to introduce you to the basics of MIPS assembly programming using xspim, a MIPS simulator.
All that hello.s does is to print "hello world!" and then exit. The program uses MIPS assembly pseudo-instruction la $a0, msg, which loads register $a0 with the memory address where msg is held. Printing (and exiting) is done by the special instruction syscall. For now, think of syscall as a special procedure call which is already provided by xpsim. You will get a more complete picture when exceptions and interrupts are discussed later in this course.
The exact task that syscall performs depends on the value stored into register $v0. To find out what other syscall options are made available by spim, see page A-44 of Appendix A of the Patterson and Hennessy book. We will be using some of these for input/output.
Load hello.s into spim.
Step through the program using the "step" button, observing the changes to the registers and the currently executed instruction. A few instructions that are not part of your program are executed before "main" is called. You don't have to understand how this part works yet. The first instruction of your program that gets executed is the one marked with the label "main".
Use the hello.s program to familiarise yourselves with the buttons and menus available in xspim.
Open hexOut.s in an editor and try to understand what it does. The first two syscalls prompt the user for a number and get the number from the keyboard. Then a message is printed. The remaining of the program, extracts each hexadecimal digit from the provided number, converts it into the corresponding ASCII character and prints it (using yet another syscall). This is done eight times, as there are 8 hex digits in a 32-bit word.
Use xspim to load and step through the program to find out exactly what each instruction is doing. Set a breakpoint (explained in the spim tutorial) at the instruction just before the label "loop", so that you can let the program run through quickly the part where it asks for input and focus on what happens in the loop.
Informatics Forum, 10 Crichton Street, Edinburgh, EH8 9AB, Scotland, UK
Tel: +44 131 651 5661, Fax: +44 131 651 1426, E-mail: firstname.lastname@example.org
Please contact our webadmin with any comments or corrections. Logging and Cookies
Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh