gwen (gwenix) wrote,
gwen
gwenix

  • Mood:

yayyyyyyyyyyyyyyyyy!!!!

So, as a few of you know, I've been stressing mightily over my Assembly class the past week. I've tried sitting down and getting the assignment done, and failed to understand the first thing about what's needed. I've asked for help from multiple sources, but I'm just so clueless, I was lost even with the help.

But! I sing praises and happiness to the God that is my TA! I was not the only one in the class THOROUGHLY confused by everything, and he patiently answered our questions and requests for examples, and everything! I now get it! In fact, I sat down at the Beehive post-class and pretty much wrote up the program in an hour. (Well, minus debugging and etc). Yay!

Also, the TA agrees that the book is pretty much crap, the first assignment is way too much for us to be doing at this stage, and he's been pushing the professor for an extension for us to get this done as well. He rules! Yay my TA!


Here's the code we're supposed to translate into MIPS Assembly:

main()
{
  int j, k, temp, min;
  int length = 9;
  int list[] = {7, 9, 4, 3, 8, 1, 6, 2, 5};

  printf("Before Sort:\n");
  for (k=0; k<length; ++k)
    printf("%d ", list[k]);
  for (k=0; k<length-1; ++k)
  {
    min = k;
    for(j=k+1; j<length; ++j)
      if (list[j] < list[min] )
        min = j;
      if (min!=k)
      {
        temp=list[min];
        list[min] = list[k];
        list[k] = temp;
      }
  }
  printf("\n\nAfter Sort:\n");
  for(k=0; k<length; ++k)
    printf("%d ", list[k]);
  printf("\n");
}


Yes, it's a selection sort. Yes, the professor would love us to do it with a stack treatment. Yes, the TA actually exclaimed, "DO NOT DO THIS AS A STACK! It is the better programming way, but you are not ready for it!" Oh, and btw, 90% of the class doesn't know C. Right on!

Me, I went back to my BASIC days (ah, those were the days), and just set it up with a series of Labels to bounce around at each other. I decided that I'd use $a0 and $a1 to indicate the current placeholders for the array elements I'm looking at, pull in from memory, swap if needed, write back out to memory. Bing bang boom, I think the code (minus the output parts) is about 20 lines long. Plus, I decided to not use pseudo-instructions just for the hell of it so that I'm used to what is or isn't those, so I think that ends up being pretty elegant. Very proud of myself I am. :)


Of course, this is all pre-debugging, so we'll see if I feel so good about it all when I sit down to do that part.
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 1 comment