All pastes #228610 Raw Edit

shineyfactor

public text v1 · immutable
#228610 ·published 2006-10-30 04:38 UTC
rendered paste body
.data

messageSize:
           .word    20
           
           .align   2
message:   .asciiz  "Four score and seven"

pattern:   .word    0x57243C7A

# Your code goes below this line

dataLine:      .asciiz  ".data\n"
numCodeLine:   .asciiz  "numCodeWords:\n"
codeWordsLine: .asciiz  "codeWords:\n"
wordLine:      .asciiz  "        .word "
newLine:       .asciiz  "\n"

.text

         # prologue
         subu      $sp, $sp, 24
         sw        $fp, 0($sp)
         sw        $ra, 4($sp)
         addiu     $fp, $sp, 24

         # load a counter (0-3) into register $s7
         li        $s7, 0

         # load another counter (0-20) into register $s6
         li        $s6, 0
         
         # load message into register $s0
         la        $s0, message

         # load messageSize into register $s1
         la        $t0, messageSize
         lw        $s1, 0($t0)

         # load pattern into register $s2
         la        $t0, pattern
         lw        $s2, 0($t0)

         # load a code word counter into register $s5
         li        $s5, 0

         # first loop : loops through the entire message using messageSize
         # and the 0-20 counter
    loopBegin:
         beq       $s1, $s6, loopingEnd
         
         # load the first four bytes of $s0 into $t3
         lw        $t3, 0($s0)

         # xor these bytes and put the result into $t2
         xor       $t2, $t3, $s2

         # store the value into $s0 again
         sw        $t2, 0($s0)

         # increment the counter by 4
         addi      $s6, 4

         # increment the number of code words counter by 1
         addi      $s5, 1

         # move the address over by 4 bytes
         addi      $s0, 4
   
         # jump back to the beginning
         j loopBegin

    loopingEnd:

         # print out the data part of the output, along with a blank line after it
         la        $a0, dataLine
         li        $v0, 4
         syscall

         la        $a0, newLine
         li        $v0, 4
         syscall

         # print out numCodeLines:
         la        $a0, numCodeLine
         li        $v0, 4
         syscall

         # print out wordLine
         la        $a0, wordLine
         li        $v0, 4
         syscall

         # print out the number of code words
         la        $a0, $s5
         li        $v0, 1
         syscall