COMP226 Practical 4



The first two questions in this week's prac are designed to show you the result of typical annoying errors that can arise and what to notice when debugging. You should work through them pretty quickly.

  1. Look at the mispelt-label.s, which has one of the labels in the source mispelt.

    Assemble, link and run this program.

    Remember this to help you debug!

  2. Look at unaligned-access.s, which is supposed to loop through a string (doing nothing), but uses ld instead of ldub.

    Assemble, link and run this program.

    Run it and notice what happens. Remember this to help you debug!

  3. Write a program which adds up the numbers in an array stored in memory. Use directives like
    	
    	.align 4
    arry:	.word 2, 5, 8, 13, 17, 21
    size:	.word 6
    result: .word
    
    in your .data section, and write your answer to result.

    Your code should work for any (reasonably sized) array, from 0 entries up to as many as you can fit in memory and add up without overflowing a 32 bit signed word.

  4. Write a program which counts the number of 1 bits in a word. Load the word from memory, and write the result to memory.

    For example, if the input word is 19, your result should be 3, since 19 = 10011 in binary, and this contains 3 ones.

  5. Write a program which reverses a string stored in memory and prints it out. With the following directive in your program
    msg:	.asciz "Buy me a pony"
    
    your program should print
    ynop a em yuB
    
    You should print your string using trap 6 (i.e. not just printing it one character at a time).

    For bonus pride, do it without using any extra memory.

  6. The Fibonacci numbers are defined by

    Write a SPARC program which reads the word value of the memory location labelled n, and prints the value of the nth fibonacci number. For this exercise, do not use recursion. Run your program to calculate the 30th Fibonacci number and note the number of cycles required.


Robbie, Kate and Mike.

Comp226 August 2013