Last active
November 20, 2019 09:41
-
-
Save frankli0324/49a9ec78fa91077046ecb7ea87912294 to your computer and use it in GitHub Desktop.
计组作业
This file contains 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
.data | |
data: | |
.text | |
.globl main | |
main: | |
la $t2, data | |
$read_loop: | |
li $v0, 5 | |
syscall | |
sw $v0, 0($t2) | |
addi $t2, $t2, 4 # sizeof(int) == 4 | |
addi $s0, $s0, 1 # cnt_input++ | |
bne $v0, 0, $read_loop | |
addi $s0, $s0, -1 | |
li $t0, 0 # $t0 = i | |
li $t1, 0 # $t1 = j | |
addi $s1, $s0, -1 # $s1 = len - 1 | |
li $s2, 0 # $s2 = 0 | |
$L0: | |
li $t1, 0 | |
bne $t0, $s1, $L1 | |
li $t2 , 0 | |
beq $t0, $s1, $output_result | |
$L1: | |
sub $s3, $s1, $t0 # $s3 = len - 1 - i | |
beq $t1, $s3, $L0 | |
$L2: | |
beq $t1, $s3 , $end_inner | |
la $t2, data | |
sll $t3, $t1, 2 | |
add $t4, $t2, $t3 | |
addi $t5, $t4, 4 | |
lw $t6, 0($t4) # $t6 = data[j] | |
lw $t7, 0($t5) # $t7 = data[j + 1] | |
addi $t1, $t1, 1 # j++ | |
# if data[j]>data[j+1] then swap(data[j], data[j+1]) | |
ble $t6, $t7, $L2 | |
add $s4, $t6 , 0 | |
sw $t7, 0($t4) | |
sw $s4, 0($t5) | |
bne $t1, $s3 , $L2 | |
$end_inner: | |
addi $t0, $t0 ,1 #$t0 = i + 1 | |
j $L0 | |
$output_single: | |
la $s1, data | |
sll $t3, $t2, 2 | |
add $t3, $t3, $s1 | |
lw $a0, 0($t3) | |
li $v0, 1 | |
syscall | |
li $a0, ' ' | |
li $v0, 11 | |
syscall | |
addi $t2, $t2, 1 | |
$output_result: | |
bne $t2, $s0, $output_single | |
jr $ra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment