1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| .data num1: .space 300 num2: .space 300 num3: .space 300 str_space: .asciiz " " str_enter: .asciiz "\n"
.macro getIndex(%dst,%row,%i,%j) mult %row,%i mflo %dst addu %dst,%dst,%j sll %dst,%dst,2 .end_macro
.macro readInt(%dst) li $v0,5 syscall move %dst,$v0 .end_macro
.macro printStr(%dst) li $v0,4 la $a0,%dst syscall .end_macro
.text readInt($s0)
li $t7,0 read1_for_i: beq $t7,$s0,read1_for_i_end li $t8,0 read1_for_j: beq $t8,$s0,read1_for_j_end readInt($t0) getIndex($t1,$s0,$t7,$t8) sw $t0,num1($t1) addi $t8,$t8,1 j read1_for_j read1_for_j_end:
addi $t7,$t7,1 j read1_for_i read1_for_i_end:
li $t7,0 read2_for_i: beq $t7,$s0,read2_for_i_end li $t8,0 read2_for_j: beq $t8,$s0,read2_for_j_end readInt($t0) getIndex($t1,$s0,$t7,$t8) sw $t0,num2($t1) addi $t8,$t8,1 j read2_for_j read2_for_j_end:
addi $t7,$t7,1 j read2_for_i read2_for_i_end:
li $t7,0 ini_for_i: beq $t7,$s0,ini_for_i_end li $t8,0 ini_for_j: beq $t8,$s0,ini_for_j_end getIndex($t1,$s0,$t7,$t8) sw $0,num3($t1) addi $t8,$t8,1 j ini_for_j ini_for_j_end:
addi $t7,$t7,1 j ini_for_i ini_for_i_end:
li $t7,0 com_for_i: beq $t7,$s0,com_for_i_end li $t8,0 com_for_j: beq $t8,$s0,com_for_j_end li $t9,0 com_for_k: beq $t9,$s0,com_for_k_end getIndex($t0,$s0,$t7,$t9) getIndex($t1,$s0,$t9,$t8) lw $s1,num1($t0) lw $s2,num2($t1) mult $s1,$s2 mflo $s1 getIndex($t0,$s0,$t7,$t8) lw $s2,num3($t0) addu $s1,$s1,$s2 sw $s1,num3($t0) addi $t9,$t9,1 j com_for_k com_for_k_end: addi $t8,$t8,1 j com_for_j com_for_j_end: addi $t7,$t7,1 j com_for_i com_for_i_end:
li $t7,0 prt_for_i: beq $t7,$s0,prt_for_i_end li $t8,0 prt_for_j: beq $t8,$s0,prt_for_j_end getIndex($t1,$s0,$t7,$t8) lw $t2,num3($t1) li $v0,1 move $a0,$t2 syscall printStr(str_space) addi $t8,$t8,1 j prt_for_j prt_for_j_end:
printStr(str_enter) addi $t7,$t7,1 j prt_for_i prt_for_i_end:
|