XML

kent logo

CO527 Anonymous Questions and Answers

This page lists the various questions and answers. To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

We have taken the liberty of making some minor typographical corrections to some of the questions as originally put. Although most of the questions here will have been submitted anonymously, this page also serves to answer some questions of general interest to those on the course.


Question 21:

Submission reference: IN277

Im not entirely sure how we seperate the strings in the array or at least break them apart into words, you say they are terminated by a null value?? do we search for this value? if so how do we then split, none of the exercises that you have show this kind of string manipulation. I'm really stuck, I've been doing this for more than 24 hours in total now, I've spent the majority of the past 5 days working on it. Can you give me some kind of tip. Thanks

Answer 21:

The array, defined on line 31, is a null-terminated array of words (indicated by the .word directive). The null-terminator is the zero value at the end (generally, null is zero, but means an invalid pointer rather than the literal value 0). The non-null words in that array (i.e. those defined with the labels "s1STR" etc.) are pointers to strings -- if you look at the data display in SPIM, you'll see the real values of these, that are the addresses at which the strings start in memory.

When talking about null-terminated strings (technically it should be "nil-terminated", but "null-terminated" is what the world uses, so..), the "null" refers to the zero byte at the end. The .asciiz directive adds this automatically to the end of the string, the .ascii directive does not. The null-character is needed so that you know when you've reached the end of the string; otherwise the program would probably just search through memory until it found a zero (by chance), or crash the program by accessing an invalid address -- not an uncommon bug in C programs. If you look at where the strings are in memory in the SPIM display, you'll see this zero/null byte on the ends of them. So, yes, you do need to look out for this null byte, for the purpose of knowing where the end of the string is.

The 8th exercise, and some of the code in sortstrings.s itself, do more or less the sort of thing that is required already. The only real difference is that on the strings themselves you're dealing with byte-sized quantities, whereas on the array of words you're dealing with word-sized (pointer-sized) quantities.

Keywords: mips-asm

Referrers: Question 39 (2005) , Question 59 (2005) , Question 67 (2005)


Question 22:

Submission reference: IN290

I'm worried that some people could actually write this in C, pipe it through a mips cross-compiler, and then compiler will spit out assembly, thus avoiding learning mips. will you be looking for this when you check for plagerism?

Answer 22:

People could do, but it'd be pretty useless. Bear in mind that gcc's calling convention might not be the same as you've been shown (indeed, it tends to use the frame-pointer, so that's a dead giveaway). Also, the optimisations that a compiler might perform are usually fairly obvious too. But by far the most obvious fact will be that there are no comments in the generated code (and if someone could be bothered to comment it, they would have to understand the code -- at which point they might as well have written it anyway).

Keywords: mips-asm


Question 23:

Submission reference: IN291

When I run sortstrings.s (with or without my algorithm), the console displays:

    *** PANIC ***
    panic code 0x0000002a at address 0x0044000a8
    please contact your OS vendor :)

It seems to be an intentional call in your supplied assembler. I'm not panicing, but do I need to fix this?

Answer 23:

Nope, you can ignore that mostly. The reason it's in there (for all options) is that an operating-system would never normally "exit", same for most embedded code too. Thus, if the code ever reaches the end of "main", it panics. The normal exit routes for an OS would be halting the machine or rebooting. In a real OS you'd probably have the panic routine print processor registers and other useful things.

Keywords: mips-asm


Question 24:

Submission reference: IN292

I have this sort of code:

    lbu     $t0, $v0($a0)                  #; load byte from string

now if I swap "$v0" just to a "0" in the lbu lines it works, as, as far as i understand this loads the byte in position 0 from the string, however I can't seem to use a variable to cycle through on loops? how do i do this ? or have i got the syntax maniacally wrong ?

Answer 24:

Yes, you can't do what you're trying to do -- look at the instruction encoding for a load instruction, it takes two registers and an constant offset (5th architecture lecture). The code in exercise 8 (ex8.s) does something similar, execept it's more interested in words than bytes, but the principle is the same.

Keywords: mips-asm

Referrers: Question 67 (2005)


Question 25:

Submission reference: IN288

Why do i get this?

    Can't expand stack segment by 8 bytes to 524288 bytes
    Use -lstack # with # > 524288

And how do i stop it ?

Answer 25:

I've seen this error from two things:

Keywords: mips-asm

Referrers: Question 31 (2005)


Question 26:

Submission reference: IN289

how do i put words that i have loaded in memory back into an array?

Answer 26:

By using "sw" (store-word) instead of "lw" (load-word), pretty much. Although the program defines these as constant addresses (using labels), the code can change them at run-time. Be careful of your terminology -- by "loaded in memory" I'm thinking you really mean "loaded in registers"; the array is in memory.

Keywords: mips-asm


Question 27:

Submission reference: IN293

in ex5, i'm trying to learn but i can't see why i need these commands in the solution nor where they came from, or how i should know about them

    subu    $sp, $sp, 4               #; drop stack for saved registers
    sw      $ra, 0($sp)               #; save return-address
    ...
    lw      $ra, 0($sp)               #; load saved return-address
    addi    $sp, $sp, 4               #; restore stack-pointer

Answer 27:

The reason for this code is given in the [exercise] question, "Hint: the call to 'do_more_math' will overwrite the $ra register, so best to save it somewhere first.". The stack is used to store things like this -- see page 23,24 in the spim documentation (although we're not interested in the frame-pointer). Reading the spim documentation and the factorial example on the assessment page would show you what and why these are.

Keywords: mips-asm


Question 28:

Submission reference: IN302

Does all of the code have to be our own? or can we adapt a bubble sorting algortihm from google to compare things and then place an acknowledgement to the source in our comments?

Answer 28:

The code should be entirely your own.. As for adaption of algorithms, well, I've already given you the C/Java code for a bubble-sort, so if you found something like that feel free to use it as the basis of your assembler implementation (and acknowlege the source). You say "adapt a" .. "to compare" -- I don't think these are compatible. Adaption implies that some of their code ended up in your program, or at least the structure/style did; comparison means your code is entirely your own and you just compared it with an existing implementation (which is fine in theory, but you would need to be very careful to avoid what is potentially plagerism -- i.e. looking at their code first, before writing your own). If you do look/use other code, make sure you acknowlege the source (not doing so starts near plagerism and finishes near gross copyright violation).

Keywords: mips-asm


Question 29:

Submission reference: IN303

I dont understand the purpose of nop or why you place it in places? Could you explain a little please. Thanks

Answer 29:

See the answer to Question 18 (2005).

Keywords: mips-asm


Question 30:

Submission reference: IN313

When is the exact time for the submission deadline?

Answer 30:

Early Friday morning of the 24th (approximately 00:01). So get your submissions in on the Thursday.

Keywords: mips-asm


Question 31:

Submission reference: IN316

"Note: building spim/xspim for myself on Debian wasn't entirely pleasant; but if you're up to it, it looks a bit better when linked against the 3D Xaw library." For those having trouble compiling spim for Debian (like me), you can just apt-get it (it's in the official repositories). It's only version 6.5-1 though, is it ok to use this to do the assessment? Could you post the Imakefile you used to build xspim? Thank you

Answer 31:

Unfortunately 6.5 has some fairly significant bugs (which will probably break the assessment). See Question 25 (2005). The Imakefile I used is the default -- just copy/paste the linker line and edit the libraries linked (Imakefiles should have been deprecated a long time ago in favour of autotools...).

Keywords: mips-asm


Question 32:

Submission reference: IN317

  1. How do I determine whether to use the 't' or 's' registers in my assembler?
  2. When I use the jal operation, should I copy the parameters required from the 's' or 't' registers to the 'a' registers?

Thanks

Answer 32:

  1. Both are temporaries, the difference is that $t0-$t7 are not saved across calls, where as $s0-$s7 are. This is just convention however. If some code you write trashes $s0-$s7, then it ought to save and restore them appropriately (so whatever routine called it won't see the contents of its own $s0-$s7 trashed).
  2. Again, convention. Yes, you should. However there's technically nothing stopping you from using other registers, but it would be bad practice not to use $a0-$a3 for parameter passing.

Keywords: mips-asm

Referrers: Question 41 (2005) , Question 59 (2005)


Question 33:

Submission reference: IN318

Less of an anonymous question, more of an anonymous hint. :-)

Hopefully this will be useful to other OS X users. Don't be tempted to download Berkley's drag and drop DMG image off the net - it's a seriously old version (4.4). You need to compile from source. Grab the files off of the main SPIM site and then follow this really easy guide - http://www.ccs.neu.edu/home/bschory/spim_macosx.txt It's much easier than the guide on the main SPIM site (and less work ;-D).

Another thing. When using XSPIM, you can drag the scrollbars by holding option(Alt) while clicking. For this to work you need to make sure the 3 button mouse emulation is enabled in the X11 preferences.

Answer 33:

Keywords: mips-asm , os-x


Question 34:

Submission reference: IN320

Hi, I'm having a strange problem defining constants with SPIM on Linux. If I do something like:

    testw1:  .word  4042322160, 65535

the values that end up in SPIM's data display are 0x7fffffff and 0x0000ffff, when they should be 0xf0f0f0f0 and 0x0000ffff. Any ideas ?

Answer 34:

This is caused by a slight bug in SPIM's parsing of decimal integer values. In general it's better to specify constants like this in hexidecimal, e.g.:

    testw1:  .word  0xf0f0f0f0, 0x0000ffff

which makes it a lot easier to see what's going on than their decimal equivalents do. This also works around the bug in Linux (windows seems to be OK with this). The problem is that SPIM is interpreting decimal values as signed integers, and 4042322160 is bigger than the biggest signed 32-bit integer, so gets truncated (to 0x7fffffff). The other workaround would be to give it the signed decimal equivalent, -252645136; but this might cause a problem for SPIMs on other platforms. Better to use hexidecimal constants.

Keywords: mips-asm


Question 35:

Submission reference: IN323

Oh, i have a hint. For those of you using windows who want slightly more than PCspim/notepad, have a look at Mipster from: http://www.downcastsystems.com/mipster/.

Its got syntax highliting and help on the right, its a nice simple little IDE, that also has SPIM built in, you just click a button and it fires it off! Its only a 30day trial, but hey, this projects due end of next week!!!

Answer 35:

Keywords: mips-asm


Question 36:

Submission reference: IN325

If the majority of marks are below say 50% or that a large proportion of people fail to submit anything, will you be altering your marking criteria / bellcurving this assesment?

Answer 36:

I'm hoping that won't be the case (I've certainly not got any reason to suspect so at the moment). As per standard practice, no, the marks for this assessment will not be fitted to a normal distribution -- imo that is not a good thing. If the average mark is low (below 55%) then there might be some cause for later adjustment, but such things are dealt with by the examinations board. If people don't submit anything they should expect a mark of zero (with exceptions for special cases).

Keywords: mips-asm


Question 37:

Submission reference: IN326

Is this the output your looking for, for an assesment, or do you want it to cope with capitilazation of the M in MIPS??

Hello SPIM world!
*******************************
all your base
are belong to us
you have no chance to survive
make your time
all your MIPS assembler
0123456789
all your base

*******************************
*******************************
0123456789
all your MIPS assembler
all your base
all your base

are belong to us
make your time
you have no chance to survive
*******************************

Answer 37:

See the answer to Question 20 (2005); the output you have there looks ok however.

Keywords: mips-asm


Question 38:

Submission reference: IN327

Thanks for the marking breakdowns, I have one minor question... Take for example string sorting - will a decent stab at quicksorting get you the whole 20%, or will it be marked out of 20, ie, if you'd give the quicksort 18/20, you get 18% extra?

Answer 38:

The marks will be allocated in (x/30) + (y/20) + ... fashion. If you have a broken quicksort you will get some marks for the quicksort (unless it's completely off-target) but probably lose some marks for the "correct sort implementation". If you know you have a broken quicksort, you could just include the code for it separately (and use a simpler, working, sort implementation to get the marks for that bit); I'll still mark the quicksort code (but you wouldn't get 20/20 unless it was wired in and working perfectly).

Keywords: mips-asm

Referrers: Question 40 (2005)


Question 39:

Submission reference: IN328

I have had a good look around and can't seem to find much information on comparing 2 strings . Could you help point me in the right direction as I really don’t have a clue on how to go about comparing strings.

I am also having the same problem with finding documentation on indexing array elements. I have done a few tutorials on google but they don’t seem to be much help with string comparison and array

Answer 39:

See the answers to Question 21 (2005) and Question 20 (2005). Comparing strings is mostly a matter of comparing the individual characters in the strings. The comparison routine should return a value indicating the relation (normal is <0, 0, >0, depending on whether the first string is, respectively, less-than, equal-to or greater-than the second). The strings in this MIPS assembly language (and many others) are arrays of bytes, where each byte is an ascii value representing a particular character ("man ascii" on most UNIX systems will show you the table). The routine itself can be coded as a single for-loop in C or Java; if you are unsure of how to go about it in assembler, try coming up with the C or Java version first (and translating from that).

Keywords: mips-asm

Referrers: Question 59 (2005) , Question 79 (2005) , Question 80 (2005) , Question 82 (2005)


Question 40:

Submission reference: IN329

For the string sorting assesment, I've succesfully implemeted a Bubble sort, would it be best if I submitted this, and then submitted another file, say QuickSortAttempt.s for my go at improving it to use a quicksort. I just dont want to lose marks for submitting a quicksort that doesnt work, when i could have submitted a fully workign bubble sort!!

Your suggestion on this will be appreciated. Thanks

Answer 40:

See the answer to Question 38 (2005).

Valid CSS!

Valid XHTML 1.0!

Maintained by Fred Barnes, last modified Thu May 8 12:58:03 2014