MIPS stuff May 8, 1999 ***************************************************************************************** Below are a few tips that I hope you will find useful for the MIPS assignment. * Put comments!!! * Write the corresponding C++ code first * You don't need subroutines for this assignment (i.e. you will not need to use jal or jr...) ***************************************************************************************** Problem 1: The size of the table should be a constant i.e. in the data section define the table in the data section. Remember to use .word for the type of data stored. Use branching wisely, remember that a branch can correspond to an if or a loop... so you will need 3 branching instructions for this one. ***************************************************************************************** Problem 2: When you do a division, the remainder, which is what interests you, is stored in the HI register. Simply check if the remainder is equal to zero or not to find if the number you're testing is a divisor or not. To move things out of the hi register in order to do the testing, simply use mfhi. Also, keep a running sum of all the divisors for a given number and check in the end if the sum is equal to that number, then loop again for thne next number (do this for all numbers between 5 and 500). ***************************************************************************************** Problem 3: The palindrome problem. You will need to: -get the input from the user -NOT modify the input (i.e. don't first change evrything to lowercase with no spaces and then check if it a palindrome) -NOT use the ascii values of the characters that you are checking for (in order to skip them) ***************************************************************************************** Tips from Chris Morrison ***************************************************************************************** Subject: a useful spim trick... Hello, If you modify a mips program, it will correctly load and run IF you 'reinitialize' spim before loading the new version, as in: (spim) reinitialize (I believe that's the syntax).... If it still seems that the program changes "haven't taken effect", try quitting spim, restarting it, and then loading the new program version... ANOTHER POSSIBLE PROBLEM: if you're getting 'unaligned address' messages, try throwing in some .align 2 directives in the .data section before each labelled directive (table, n, stringspace, etc...) ***************************************************************************************** Subject: reading spim's debugger output... Hi, This might help - notes on what you see when you use spim's 'step' command: (spim) step [0x00400000] lw $4, 0($29) $04 = 0x00000000 # shows machine lang. # version of instr. just executed, and # the contents of the result register addiu $a1, $sp, 4 # argv # this is the instr ABOUT to execcute (spim) [0x00400004] addiu $5, $29, 4 $05 = 0x7ffff000 # now that instr addiu $a2, $a1, 4 # envp # has executed, we see it in spim's (spim) # machine lang version (which takes # some sleuthing to figure out - the # # internal notation is tricky) # $5 is $a1, $29 is $sp... there's a # table of reg. nums. in the manual ***************************************************************************************** Subject: Makefile troubles for both Mips and project... Hello, There was a bug in both Makefiles that has been repaired. For things to work correctly, recopy ONLY THE MAKEFILE into the same directory in your account as the appropriate program files, as follows, and all should be well: ice ~/unit8 % cp ~libe50b/unit8/assign/Makefile . or... ice ~/grad % cp ~libe50b/grad/assign/Makefile . In both cases, don't forget that 'space, dot' at the end of the command! ***************************************************************************************** Subject: generating demo output with SPIM... Hello, The early instructions (link posted on website and login notice) for using make & submit for the MIPS assignment have been corrected to reflect the fact that SPIM WON'T RUN DURING A 'script' SESSION! But 'spim' will do the same job, as described below... We apologize for any inconvenience! -Chris M ... this is the essence of the correction: GENERATING DEMO OUTPUT WITH SPIM Unfortunately, spim won't run during a 'script' session; fortunately, spim has its own built-in way of generating demo files. Suppose I wanted to make a demo for minmax.asm: o I'd get spim started, load in minmax.asm, then, (spim) dribble "minmax.out" ... start SPIM's "scripting" facility (spim) run ... run minmax as necessary to demo it ... (spim) dribble ... stops "dribbling", leaving the file minmax.out in my directory, containing the entire interaction just as 'script' does for C++ programs. Note that a list of spim commands appears when one asks spim for help: (spim) help