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

Загрузка

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

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

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

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