Some aspects of writing assembly language programs:

1. Make use of comments generously. Since assembly languagecan be so arcane it is best for everyone concerned to have meaningful comments.Comments start with # and last till end of line much like the // in c/c++
2. All integer/float/string declarations should be doneafter the ".data" line. eg:

        .data
        str1:
               .asciiz    "Hello world.\n"

        This definesa null terminated string str1. \n , \t have the same meaning as in c.

        num1:
               .word    34    #Same as int num1 = 34;
 

3. Instructions start with  the ".text" and"__start:" lines. eg:

        .text
        __start:   #Equivalent to main()
4. There are some basic system call that can be used. These have been mentioned in Patterson/Hennessey appendix A49

You can download the pdf version of the appendix via my webpage

Download THIS

Using XSPIM to debug and run assembly programs :

1. Start a session of Xwin32 by clicking the Xwin32 icon.
2. SSH onto program.cs.fsu.edu using your diablo login names and passwords.
(If you are working from home you will have to set your display to your home machine)
3. Preferably go to the directory where you have the assembly programs.
4. type xspim &.

This will open the xspim interface.
a.    The top half of the display shows values of allthe registers which change as the program is run in the simulator.
b.    Below the registers are some useful buttons whichwe will consider as we start using the simulator to test a few programs.
d.    Below this is the Data segment pane.
e.    Below the Data segment pane is a window whereSPIM will print the error messages.

Loading An Assembly Program:

Press the "load" button, a window will come up asking you for a filename.Type in the name of your program and press "assembly file". xspim willproceed to load and assemble your program. You can also enter the relativepath name of the file like  ~thomas/cda3101/hello.s

Executing An Assembly Program

If there are any errors in your program then xspim will display the errorsin the Message pane which is just just below the Data segment pane.
Each time you run a program, you need toBe sure to check the Message pane at the bottom of the xspim window afterthe load step - this is where assembly errors are reported. If you tryto run a program that did not assemble correctly, you will get strangebehavior
 

Debugging An Assembly Program

Debugging with xspim amounts usually to single stepping through each instructionin your program and observing the changes in the state of the registers.To step through your program you must first declare a breakpoint. Whenxspim reaches the breakpoint it halts and lets you view all the registercontents. After observing the state, you may tell xspim to finish executingyour program in its entirety (or until it encounters another breakpoint),or you may step through your program line by line.

Setting breakpoints:
To set a breakpoint you must first observe the address of the instructionwhere you wish to suspend execution (remember, the address is the firstcolumn of the Text segment pane in the xspim window). Next, press the "Breakpoints"button, then type in the address of the breakpoint and press "add". Whenyou run your program, xspim will suspend execution at the breakpoint thatyou specified. To continue execution of your program, press the "Step"button, this brings up the step window, which allows you to either stepthrough your program (press the "step" button) or continue execution ofyour program (press the "continue" button).

Note that it is possible to set multiple breakpoints, the List buttonin the Breakpoints window shows all the current breakpoints set by theuser.
 

Some control buttons in XSPIM:

1. quit: Quit from XSPIM
2. load: load assembly program. ie .s file
3. run: run program. Remember to clear register and memory contentsand reload the program if the program has been     changed.
4. step: single stepping used with breakpoints to debug the program.It asks for the step size ie "Number of steps" which is the no. of instructionswhich will be performed every time step is clicked. Its best to leave itto 1 and click ok
5. clear: used to clear register and/or memory.
6. set value: can be used to set the value of any register which maybe required by the program. eg set $s1 = 5
7. print: can be used to print various memory locations or global symbolsused.
8. breakpoint: as explained earlier it is used to set/delete/list breakpoints.