0706.205.01 Computer Organization

Homework 3

Fun with spim, and other things


Due Date

Friday, April 19 (11:59pm)

Form of Submission

Homework must be submitted via email.

Preparation

Patterson & Hennessy. Section 4.1-4.5; Appendix Section A.9

Question

  1. Consider the truth table for a 1-bit adder on Slide 13 of the April 10 lecture. In the manner of the CarryOut formula (Slide 14), produce a logical formula (composed of ANDs and ORs) for the 1-but Sum.

  2. Below is the subprogram from the midterm, adapted to run inside spim, the MIPS simulator. Save it to a file on Elvis, and run it inside the simulator.
    1. Change the program so that instead of turning its input (the contents of memory addressed by register $a0) into all upper-case, it turns it into all lower-case.
    2. Email me the modified program.
            .data
    str:
            .asciiz "Hello"
    orig:
            .asciiz "\nThe input: "
    now:
            .asciiz "\nThe output: "
    v0:
            .asciiz "\n  $v0 = "
    end:
            .asciiz "\n\n"
            .text
    START:  
            add     $v0, $zero, $zero       
    
    LOOP:   lb      $t0, 0($a0)
            beq     $t0, $zero, DONE
    
            addi    $sp, $sp, -12           # allocate space on stack
            sw      $a0, 0($sp)
            sw      $ra, 4($sp)
            sw      $v0, 8($sp)
    
            add     $a0, $t0, $zero
            jal     DOIT
    
            lw      $a0, 0($sp)
            lw      $ra, 4($sp)
    
            sb      $v0, 0($a0)
            lw      $v0, 8($sp)
            addi    $a0, $a0, 1
            addi    $v0, $v0, 1
            addi    $sp, $sp, 12
            j       LOOP
    
    DONE:   jr      $ra
    
    
    DOIT:   add     $v0, $a0, $zero
            slti    $t2, $v0, 97
            bne     $t2, $zero, SKIP
            slti    $t2, $v0, 123
            beq     $t2, $zero, SKIP
            addi    $v0, $v0, -32
    
    SKIP:   jr      $ra
    
    
    
    __start:
            addi    $v0, $zero, 4
            la      $a0, orig
            syscall
    
            li      $v0, 4
            la      $a0, str
            syscall
    
            la      $a0, str
            jal     START
    	move	$t0, $v0	# save return value 
    
            li      $v0, 4
            la      $a0, now
            syscall
    
            li      $v0, 4
            la      $a0, str
            syscall
    
            li      $v0, 4
            la      $a0, v0
            syscall
    	
            li      $v0, 1
            move    $a0, $t0
            syscall
    	
            li      $v0, 4
            la      $a0, end
            syscall