go to previous page   go to home page   hear noise   go to next page

Answer:

No assumptions are necessary. It tests if two bit patterns are identical.


Natural If-Else Structure

When you use a branch instruction to implement an if-statement, the instructions that are executed when the condition is false immediately follow the branch instruction. This is the opposite of high-level languages. With them, an if-statement is immediately followed by the statements that correspond to "true". Watch out for this problem when you are coding. Careful documentation helps.

Here is a program fragment that is to add the value in register $t0 to register $t2 (if $t0 is even) and to $t1 (if $t0 is odd):

        lw    $t0,val          # $t0 has the value
        andi  $t8,$t0,1        # one's place in $t8 is zero or one
        
        ____  $t8,odd          # if even
                               # {
        addu  $t2,$t2,$t0      #     add to even sum
        b     endif            # }
        
odd:                           # else
        addu  $t1,$t1,$t0      #     add to odd sum
endif:

An unconditional branch instruction is used at the bottom of the true branch to skip around the false branch.

(In this chapter, the SPIM simulator has been set so that delayed branches are OFF and delayed loading is OFF, so no-ops are not included in this program fragment.)


QUESTION 5:

Fill in the blank by choosing the correct branch instruction (refer to the previous table).