Прикреплённый файл «row-major.asm»

Загрузка

   1 #############################################################################
   2 #  Row-major order traversal of 16 x 16 array of words.
   3 #  Pete Sanderson
   4 #  31 March 2007
   5 #
   6 #  To easily observe the row-oriented order, run the Memory Reference
   7 #  Visualization tool with its default settings over this program.
   8 #  You may, at the same time or separately, run the Data Cache Simulator 
   9 #  over this program to observe caching performance.  Compare the results
  10 #  with those of the column-major order traversal algorithm.
  11 #
  12 #  The C/C++/Java-like equivalent of this MIPS program is:
  13 #     int size = 16;
  14 #     int[size][size] data;
  15 #     int value = 0;
  16 #     for (int row = 0; col < size; row++) {
  17 #        for (int col = 0; col < size; col++) }
  18 #           data[row][col] = value;
  19 #           value++;
  20 #        }
  21 #     }
  22 #
  23 #  Note: Program is hard-wired for 16 x 16 matrix.  If you want to change this,
  24 #        three statements need to be changed.
  25 #        1. The array storage size declaration at "data:" needs to be changed from
  26 #           256 (which is 16 * 16) to #columns * #rows.
  27 #        2. The "li" to initialize $t0 needs to be changed to new #rows.
  28 #        3. The "li" to initialize $t1 needs to be changed to new #columns.
  29 #
  30          .data
  31 data:    .word     0 : 256       # storage for 16x16 matrix of words
  32          .text
  33          li       $t0, 16        # $t0 = number of rows
  34          li       $t1, 16        # $t1 = number of columns
  35          move     $s0, $zero     # $s0 = row counter
  36          move     $s1, $zero     # $s1 = column counter
  37          move     $t2, $zero     # $t2 = the value to be stored
  38 #  Each loop iteration will store incremented $t1 value into next element of matrix.
  39 #  Offset is calculated at each iteration. offset = 4 * (row*#cols+col)
  40 #  Note: no attempt is made to optimize runtime performance!
  41 loop:    mult     $s0, $t1       # $s2 = row * #cols  (two-instruction sequence)
  42          mflo     $s2            # move multiply result from lo register to $s2
  43          add      $s2, $s2, $s1  # $s2 += column counter
  44          sll      $s2, $s2, 2    # $s2 *= 4 (shift left 2 bits) for byte offset
  45          sw       $t2, data($s2) # store the value in matrix element
  46          addi     $t2, $t2, 1    # increment value to be stored
  47 #  Loop control: If we increment past last column, reset column counter and increment row counter
  48 #                If we increment past last row, we're finished.
  49          addi     $s1, $s1, 1    # increment column counter
  50          bne      $s1, $t1, loop # not at end of row so loop back
  51          move     $s1, $zero     # reset column counter
  52          addi     $s0, $s0, 1    # increment row counter
  53          bne      $s0, $t0, loop # not at end of matrix so loop back
  54 #  We're finished traversing the matrix.
  55          li       $v0, 10        # system service 10 is exit
  56          syscall                 # we are outta here.
  57          
  58          
  59          
  60          

Прикреплённые файлы

Для ссылки на прикреплённый файл в тексте страницы напишите attachment:имяфайла, как показано ниже в списке файлов. Не используйте URL из ссылки «[получить]», так как он чисто внутренний и может измениться.

Вам нельзя прикреплять файлы к этой странице.