此代码查找子行列式,其行列式等于零但不能打印数字之间的空格和行。
如何在数字之间打印线条和空格?
这是完整的代码:
.text
.globl main
main:
la $t0,blank
add $t1,$t0,$zero
li $s5,-1
li $v0,5
syscall
add $s0,$v0,$zero #$s0=n
mul $t2,$s0,$s0 #t2=n^2
sub $t3,$t2,$s0 #t3=n^2-n, barya check nakardan e n taye akhar
voroodi:
beq $t2,0,process
subi $t2,$t2,1
li $v0,5
syscall
sw $v0,($t1) #save dar hafeze
addi $t1,$t1,4
j voroodi
process:
addi $s5,$s5,1
div $a0,$s5,$s0
mfhi $s6
subi $a0,$s0,1
beq $s6,$a0,process
beq $s5,$t3,fi
sll $s3,$s5,2 #shomarande khooneye i om e matrix
add $t4,$t0,$s3
lw $t9,($t4) #load e a1
lw $t8,4($t4) #load e a2
add $s4,$s0,$zero
sll $s4,$s0,2
add $s4,$s4,$t4 #dasresi be khoone 3vvom e determinan
lw $t7,($s4) #load e a3
lw $t6,4($s4) #load e a4
mul $s7,$t9,$t6
mul $s6,$t8,$t7
sub $s7,$s7,$s6
beq $s7,0,print
j process
print:
beq $t5,0,skip
la $a0,lines
li $v0,4
syscall
skip:
add $a0,$t9,$zero
li $v0,1
syscall
la $a0,space
li $v0,4
syscall
add $a0,$t8,$zero
li $v0,1
syscall
la $a0,next_line
li $v0,4
syscall
add $a0,$t7,$zero
li $v0,1
syscall
li $v0,4
la $a0,space
syscall
add $a0,$t6,$zero
li $v0,1
syscall
addi $t5,$t5,1
j process
fi:
bne $t5,0,finish
li $v0,4
la $a0,no_result
finish:
.data
blank:
.asciiz ""
space:
.asciiz " "
next_line:
.asciiz "\n"
lines:
.asciiz "--"
no_result:
.ascii "No such a matrix available"
答案 0 :(得分:3)
以下示例代码显示了如何在两个数字之间打印空格。根据您的需求进行调整。
# print number 1
li $a0, 1 # number to print
li $v0, 1 # syscall number for printing integer
syscall
# print space, 32 is ASCII code for space
li $a0, 32
li $v0, 11 # syscall number for printing character
syscall
# print number 2
li $a0, 2
li $v0, 1
syscall