Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To shift the element 80 to the row above in MIPS, follow these steps:

  1. Load the elements of the matrix into the memory, including the element 80.

  2. Compute the memory address of the element that you want to move. For example, if the matrix is stored in row-major order, and element 80 is in row 3, column 2, then the address would be:

    memoryaddress = matrixaddress + (3 * rowlength + 2) * elementsize

    Where rowlength is the number of columns in each row, and elementsize is the size of each element in bytes.

  3. Compute the memory address of the element above the one you want to move. For example, if element 80 is in row 3, column 2, then the address of the element above it would be:

    memoryaddressabove = matrixaddress + ((3-1) * rowlength + 2) * element_size

    Where (3-1) is the row number of the element above, and the rest is the same as before.

  4. Load the value of the element that you want to move into a register.

  5. Store the value of the element above the one you want to move into a temporary register.

  6. Store the value of the element that you want to move into the memory address of the element above.

  7. Load the value of the temporary register into the memory address of the element that you just moved.

  8. Done.

Note: This procedure assumes that the matrix is stored in row-major order, and that the elements are stored in contiguous memory locations. If this is not the case, then you will need to modify the memory access calculations accordingly.