Created
December 3, 2016 23:45
-
-
Save EmmettW/a075fbeba6fb9025ad94e1867922f947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ########################################################### | |
| # Subprogram Description | |
| # partition array | |
| ########################################################### | |
| # Arguments In and Out of subprogram | |
| # | |
| # $a0 | |
| # $a1 | |
| # $a2 | |
| # $a3 | |
| # $v0 | |
| # $v1 | |
| # $sp+0 - source array base address (IN) | |
| # $sp+4 - source array length (IN) | |
| # $sp+8 - partition value, double-precision (IN) | |
| # $sp+16 - “less” array base address (OUT) | |
| # $sp+20 - “less” array length (OUT) | |
| # $sp+24 - “greater” array base address (OUT) | |
| # $sp+28 - “greater” array length (OUT) | |
| ########################################################### | |
| # Register Usage | |
| # $t0 array base address | |
| # $t1 | |
| # $t2 size of source array | |
| # $t3 size of less than array | |
| # $t4 size of greater array | |
| # $t5 | |
| # $t6 | |
| # $t7 | |
| # $t8 | |
| # $t9 | |
| ########################################################### | |
| .data | |
| lw $t2 4($sp) | |
| l.d $f4, 8($sp) # load partition value | |
| la $t0, 0($sp) # load the address of the array into $t0 | |
| ### loop to find size of less than and greater than## | |
| find_size_loop | |
| blez $t2 next_part | |
| # do the stuff | |
| l.d $f12, 0($t0) # load value from array | |
| c.lt.d $f12, $f4 # compare and set flag if $f12 < $f4 | |
| bc1f is_greater | |
| is_less_than: | |
| addi $t3 $t3 1 | |
| addi $t0 $t0 8 | |
| addi $t2 $t2 -1 | |
| b find_size_loop | |
| is_greater: | |
| addi $t4 $t4 1 | |
| addi $t0, $t0, 8 # increment $t0 by one, to point to the next element in the array | |
| addi $t2 $t2 -1 | |
| b find_size_loop | |
| # now have the size of less than array and greater than array in $t3 and $t4 | |
| # initialize arrays | |
| ### | |
| ##### loop to transfer to the arrays | |
| ##### | |
| ########################################################### | |
| .text | |
| jr $ra #return to calling location | |
| ########################################################### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment