Better format.

This commit is contained in:
unlockable
2024-05-03 23:57:11 +08:00
parent 182a6eb8ae
commit 19d88bfaa9
5 changed files with 136 additions and 133 deletions

View File

@@ -1,10 +1,10 @@
.data
file_buff: .space 8 # A space of 2 bytes
.align 3
.align 3
input_file_name: .asciiz "a.in"
.align 3
.align 3
output_file_name: .asciiz "a.out"
.align 3
.align 3
.text
la $a0, input_file_name
@@ -35,8 +35,8 @@ syscall
li $v0, 16
syscall
li $v0 5 # read integer
li $v0, 5 # read integer
syscall
addi $a0, $v0, 10 # a0 = v0 + 10
li $v0 1 # print integer
li $v0, 1 # print integer
syscall

View File

@@ -1,26 +1,29 @@
.data
.text
li $v0, 5 # read in i
syscall
move $s1, $v0 # use s1 to store i
li $v0, 5 # read in i
syscall
move $s1, $v0 # use s1 to store i
li $v0, 5 # read in j
syscall
move $s2, $v0 # use s2 to store j
li $v0, 5 # read in j
syscall
move $s2, $v0 # use s2 to store j
sub $s1, $zero, $s1 # i = -i
sub $s1, $zero, $s1 # i = -i
bgez $s2, no_neg_j # if >= 0, then no neg
sub $s2, $zero, $s2 # j = -j
bgez $s2, no_neg_j # if >= 0, then no neg
sub $s2, $zero, $s2 # j = -j
no_neg_j: move $s0, $zero # use s0 as temp, temp = 0
count_up_j: bge $s0, $s2, done_count_up # if temp >= j, stop iteration
addi $s1, $s1, 1 # i = i + 1
addi $s0, $s0, 1 # ++temp
j count_up_j
no_neg_j:
move $s0, $zero # use s0 as temp, temp = 0
count_up_j:
bge $s0, $s2, done_count_up # if temp >= j, stop iteration
addi $s1, $s1, 1 # i = i + 1
addi $s0, $s0, 1 # ++temp
j count_up_j
done_count_up: move $a0, $s1
li $v0 1
syscall
done_count_up:
move $a0, $s1
li $v0, 1
syscall
move $v0, $s1 # set return value
move $v0, $s1 # set return value

View File

@@ -1,18 +1,18 @@
.data
.text
li $v0 5 # read in num
syscall
li $v0, 5 # read in num
syscall
move $s0, $v0 # $s0 is n
move $a0, $v0
li $v0, 9 # malloc
syscall
move $s1, $v0 # $s1 = a
move $s0, $v0 # $s0 is n
move $a0, $v0
li $v0, 9 # malloc
syscall
move $s1, $v0 # $s1 = a
move $t0, $zero # a0 = 0
move $t0, $zero # a0 = 0
move $t0, $zero # i = 0
move $t1, $s1 #t1 = a
move $t0, $zero # i = 0
move $t1, $s1 #t1 = a
read_in_num:
bge $t0, $s0, done_read_in_num # i >= n, break
li $v0, 5 # read in num
@@ -24,13 +24,13 @@ read_in_num:
j read_in_num
done_read_in_num:
srl $s2, $s0, 1 # s1 = n / 2
move $t0, $zero # i = 0
move $t1, $s1
srl $s2, $s0, 1 # s1 = n / 2
move $t0, $zero # i = 0
move $t1, $s1
subi $t2, $s0, 1 # t2 = n - 1
sll $t2, $t2, 2 # t2 *= 4
add $t2, $t2, $s1
subi $t2, $s0, 1 # t2 = n - 1
sll $t2, $t2, 2 # t2 *= 4
add $t2, $t2, $s1
reverse:
bge $t0, $s2, done_reverse # i >= n / 2, break
lw $t3, 0($t1) # t3 = a[i]
@@ -48,13 +48,13 @@ reverse:
j reverse
done_reverse:
move $t0, $zero
move $t1, $s1
move $t0, $zero
move $t1, $s1
output:
bge $t0, $s0 done_output
bge $t0, $s0, done_output
lw $a0, 0($t1)
li $v0 1
li $v0, 1
syscall
addi $t0, $t0, 1
@@ -62,5 +62,5 @@ output:
j output
done_output:
li $v0 17
syscall
li $v0, 17
syscall