CS0447 Project 4 Due April 19th midnight PROJECT: Make a small spreadsheet program that supports the following commands. x y = v - set cell x,y to value v x y S x1 y1 x2 y2 - set cell x,y to be the sum of cells x1,y1 to x2,y2 and reset previous sum cell (if there is one) to 0 q - quit Assume all values are integers. Every time a cell is changed with the = command, you should recompute the value for the sum cell (if one has been set). Some issues you will need to deal with. You don't know the size of the spreadsheet in advance, so you can't declare a variable in your program of the right size. Instead, you have to prompt the user for the number of rows and columns, and use the sbrk system call to allocate a chunk of memory of the right number of words. This system call returns a pointer to (i.e., the address of) the beginning of the chunk of memory allocated. SPIM does not support 2-dimensional arrays. You'll have to figure out how to "map" a 2-dimensional array onto the 1-dimensional chunk of memory you have allocated. Below is a small program with a procedure that will print out integers in a fixed width. You may copy this procedure so you can make your output look nice. Note that you have already written code to read a string and convert it to an integer. You should be able to reuse that code - you might have to extract your old code and put it in a procedure. If you already did put it in a procedure, you're ahead of the game. This is the way it always goes! PARTIAL CREDIT OPTION: For a maximum of 10 points: just support the = command, and print out a total of ALL cells after each command. WHAT TO SUBMIT: You will submit one file with the extension .s (an assembly language program). Copy a file called yourfirstname_yourlastname.s to /afs/cs.pitt.edu/usr0/moir/public/447/submission_4 SAMPLE RUN: Spreadsheet size? 4 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Command: 0 0 = 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Command: 0 2 = 2 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 Command: 1 2 = 15 5 0 2 0 0 0 15 0 0 0 0 0 0 0 0 0 Command: 2 2 S 0 0 1 2 5 0 2 0 0 0 15 0 0 0 22 0 0 0 0 0 Command: 1 1 = -50 5 0 2 0 0 -50 15 0 0 0 -28 0 0 0 0 0 Command: 3 0 S 1 1 3 3 5 0 2 0 0 -50 15 0 0 0 0 0 -35 0 0 0 Command: q Bye! PRINTINT procedure and test bed =============================== .data outstr: .asciiz ".........." newline: .asciiz "\n" .text main: li $a0, 1 jal printint li $v0, 4 la $a0, newline syscall li $a0, 12 jal printint li $v0, 4 la $a0, newline syscall li $a0, 123 jal printint li $v0, 4 la $a0, newline syscall li $a0, -1 jal printint li $v0, 4 la $a0, newline syscall li $a0, -12 jal printint li $v0, 4 la $a0, newline syscall li $a0, -123 jal printint li $v0, 4 la $a0, newline syscall li $v0, 10 syscall printint: li $t2, 10 slt $t4, $a0, $zero # remember if negative beq $t4, $zero, carryon # check if positive sub $a0, $zero, $a0 # get absolute value carryon: la $t0, outstr add $t0, $t0, 9 # pointer to end of output string li $t1, 0 sb $t1, 0($t0) # null terminator sub $t0, $t0, 1 # move back one character storeloop: div $a0, $t2 # divide argument by 10 mfhi $t3 # get remainder add $t3, $t3, 48 # convert to ascii sb $t3, 0($t0) # store digit mflo $a0 # get quotient sub $t0, $t0, 1 # move back one character bne $a0, $zero, storeloop # continue if more la $t5, outstr # get beginning of string beq $t4, $zero, positive # see if number is negative li $t6, 45 sb $t6, 0($t0) # write minus sign sub $t0, $t0, 1 # move back one character positive: blt $t0, $t5, printit # print it out if we've reached the beginning li $t6, 32 sb $t6, 0($t0) # store a space sub $t0, $t0, 1 # move back one character j positive # continue printit: li $v0, 4 # printout constructed string la $a0, outstr syscall jr $ra