Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- start: li $s0, 0 # i = 0
- li $t2, 15 # n = 15
- li $s1, 0 # x = 0
- li $s2, 0 # y = 0
- cycle1: sltu $t4, $s0, $t2 # if (i >= n) <---------------------
- beq $t4, 0, res # goto res ------------ |
- # else | |
- li $s1, 0 # x = 0 | |
- subu $t3, $t2, $s0 # t3 = n - i | |
- | |
- cycle2: sltu $t6, $s1, $t3 # if (x >= t3) <-------+--------- |
- beq $t6, 0, cycle1End # goto cycle1End------+--- | |
- # else | | | |
- lw $t0, 0($s1) # t0 = ram[x] | | | |
- addiu $s2, $s1, 1 # y = x + 1 | | | |
- lw $t1, 0($s2) # t1 = ram[y] | | | |
- sltu $t5, $t1, $t0 # if (t0 >= t1) | | | |
- beq $t5, 0, cycle2End # goto cycle2End -+--|--- | |
- # else | | | | |
- move $s3, $t0 # s3 = t0 | | | | |
- move $t0, $t1 # t0 = t1 | | | | |
- move $t1, $s3 # t1 = s3 | | | | |
- sw $t0, 0($s1) # ram[x] = t0 | | | | |
- sw $t1, 0($s2) # ram[y] = t1 | | | | |
- | | | | |
- cycle2End: addiu $s1, $s1, 1 # x++ <--------------+--+--- | |
- b cycle2 # goto cycle2 --------+--+------ |
- | | |
- cycle1End: addiu $s0, $s0, 1 # i++ <--------------|--- |
- b cycle1 # goto cycle1 --------+------------
- |
- res: b res # finish! <-----------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement