Homework 1

(Due Wednesday, Jan. 17)
For homework 1, you must write a "realistic" program in assembly. The program is the C program: quick_sort.c in the course directory. You can test it via:
gcc quick_sort.c && ./a.out
In addition, you must include each line of the C source code as a comment just before the corresponding assembly code. For example:
# x = y + z;
add $t4, $t2, $t1
# x -= 2;
sub $t4, $t4, 2
(There are some more examples in the hw1 directory.)

You must submit (using the on-line submit script as specified in submission guideline) your assembly source. You must submit it as a .tar.gz file that contains a single hw1.asm file.

MIPS Simulator

Please use the MARS simulator, and especially its singlestep/backstep feature. This will make your debugging much easier. Note that Mars supports various print commands as system calls (using syscall). For information on syscall, see Table 1 and Section 1.5 of SPIM documentation (also linked to from the MARS page.

Initialization of Data Structures

Note also that for this C program, you will need to initialize the array of strings: {"Joe", ...} To do so, you will need to use the assembler directives (see MARS page). The most useful directives for this are: .asciiz and .align For example:
           .align 5  # in our example, names start on a 32-byte boundary
dataName:  .asciiz "Joe"
           .align 5
           .asciiz "Jenny"
           ...
Then, array points to "Joe", array+32 points to "Jenny", etc. Once you have done this, you can then create the array, dataName[], in quick_sort.c. Rather than manipulate 'dataName', an array of strings, it is better to manipulate 'dataAddr', an array of pointers to strings. You should represent dataAddr[] as an array of addresses (pointers), where each address points to a string. So, you will initialize data as:
          .align 2  # addresses should start on a word boundary
dataAddr: .space 64 # 16 pointers to strings: 16*4 = 64
This .space directive will allocate space, but it will not initialize the space. Later, you must write code inside main() that will initialize the space so that each word starting at 'dataAddr' points to the address of the next string found at 'dataName'.

Load/Store Instructions in Assembly

Note these four variations of load/store:
sw $t1, 4($sp) # store #t1 into RAM
lw $t1, 4($sp) # load into #t1 from RAM
li $t1, $t2    # load immediate data into #t1 ($t2 should be data)
la $t1, $t2    # load address into #t1 ($t2 should be address)+