.text
.globl main
main:
addi $s0, $zero, 1 # i = 1
loop1: #for i loop
slti $t0, $s0, 10 #if(i<10)
beq $t0, $zero, exit #if(i>=10) go exit
addi $s1, $zero, 1 #else set j=1
loop2: #for j loop
slti $t0, $s1, 10 #if(j<10)
beq $t0, $zero, label #if(j>=10) go label
move $a0, $s0 #else printf i
li $v0, 1
syscall
la $a0, mul_str #printf *
li $v0, 4
syscall
move $a0, $s1 #else printf j
li $v0, 1
syscall
la $a0, equ_str #printf =
li $v0, 4
syscall
mul $a0, $s0, $s1 #else printf i*j
li $v0, 1
syscall
la $a0, spa_str #printf " "
li $v0, 4
syscall
addi $s1, $s1, 1 #j++
j loop2
label:
la $a0, ch_row #printf \n
li $v0, 4
syscall
addi $s0, $s0, 1 #i++
j loop1
exit: #exit
jr $ra
.data
mul_str: .asciiz"*"
spa_str: .asciiz" "
ch_row: .asciiz"\n"
equ_str: .asciiz"="
.globl main
main:
addi $s0, $zero, 1 # i = 1
loop1: #for i loop
slti $t0, $s0, 10 #if(i<10)
beq $t0, $zero, exit #if(i>=10) go exit
addi $s1, $zero, 1 #else set j=1
loop2: #for j loop
slti $t0, $s1, 10 #if(j<10)
beq $t0, $zero, label #if(j>=10) go label
move $a0, $s0 #else printf i
li $v0, 1
syscall
la $a0, mul_str #printf *
li $v0, 4
syscall
move $a0, $s1 #else printf j
li $v0, 1
syscall
la $a0, equ_str #printf =
li $v0, 4
syscall
mul $a0, $s0, $s1 #else printf i*j
li $v0, 1
syscall
la $a0, spa_str #printf " "
li $v0, 4
syscall
addi $s1, $s1, 1 #j++
j loop2
label:
la $a0, ch_row #printf \n
li $v0, 4
syscall
addi $s0, $s0, 1 #i++
j loop1
exit: #exit
jr $ra
.data
mul_str: .asciiz"*"
spa_str: .asciiz" "
ch_row: .asciiz"\n"
equ_str: .asciiz"="
Thanks so much
回覆刪除