COMP226 Tutorial 4



Hand-in questions

  1. What does the following program do?
        .data      
    a: .word 0x42
    b: .word 0x43
    c: .word 0x44
    
        .text
        sethi %hi(a), %r1
        or %r1, %lo(a), %r1
        ld [%r1], %r2
        set b, %r1
        ld [%r1], %r3
        set c, %r1
        ld [%r1], %r4
        
        smul %r2, %r3, %r2
        sdiv %r2, %r4, %r2
        
        set a, %r1
        st %r2, [%r1]
        
        ta 0
    
    Write a comment after each non-empty line. I've done the first line for you:
    .data                        ! place data section at default location 0x4000
    
    For each line of code, do not restate what the instruction does, instead try to explain (this might mean that you need to try to understand what the program does overall so you can explain what a single instruction contributes to that goal). (Not that the program is really very useful... Still, make sure you can describe what it does in one sentence.)
  2. Write a SPARC program which calculates triangular numbers.
    Given a number n at location num: calculate its triangular number and place the result at location tri:
    Note: You might have to do some exploration to find out what the triangular numbers are and how they are calculated, but that's OK - it's all part of your preparation for the tute.

  3. Demonstrate how you can rewrite your triangular numbers program, so the calculation of the number is done in a leaf procedure (if at all possible). And anyway, what is a "leaf procedure"?

Discussion questions

Think about these questions, and if you have time discuss them (and if you don't have time, then think about discussing them in a future week if you get time!) (You don't have to hand anything in for the following questions), but I'm happy to read what you write if you do hand something in.

  1. What are the advantages of 64 bit machines? Most current 64 bit machines use 64 bit registers and 64 bit addresses but something else, often 32 bits, for instructions. Why do you think this might be? Can you think of alternatives?

Kate and Mike, 2013 COMP226 home page