标签:读取 严格 lang 需要 pre 元素 任务 set word
使用MIPS汇编语言编写一个进行卷积运算的汇编程序(不考虑延迟槽)。
li $v0, 10
syscall
给出以下输入:
4
3
2
2
1
2
3
4
5
6
7
8
9
10
11
12
0
1
2
3
正确的输出应该是:
0000000000000000000000000000000000000000000000000000000000011001 0000000000000000000000000000000000000000000000000000000000011111
0000000000000000000000000000000000000000000000000000000000101011 0000000000000000000000000000000000000000000000000000000000110001
0000000000000000000000000000000000000000000000000000000000111101 0000000000000000000000000000000000000000000000000000000001000011
.globl main
。
1 .data 2 arr1: .word 0:101 3 arr2: .word 0:101 4 arrhi:.word 0:101 5 arrlo:.word 0:101 6 space:.asciiz " " 7 line: .asciiz "\n" 8 9 .text 10 li $v0,5 #scanf("%d",&m1) 11 syscall 12 move $t0,$v0 #t0=m1 13 li $v0,5 #scanf("%d",&n1) 14 syscall 15 move $t1,$v0 #t1=n1 16 17 li $v0,5 #scanf("%d",&m2) 18 syscall 19 move $t2,$v0 #t2=m2 20 li $v0,5 #scanf("%d",&n2) 21 syscall 22 move $t3,$v0 #t3=n2 23 24 move $s0,$0 25 move $s1,$0 26 move $s2,$0 27 read1:mult $s0,$t1 28 mflo $s2 29 add $s2,$s2,$s1 30 li $v0,5 31 syscall 32 move $t4,$v0 33 sll $s2,$s2,2 34 sw $t4,arr1($s2) #t4=a[j][j] 35 36 addi $s1,$s1,1 37 bne $s1,$t1,read1 38 39 move $s1,$0 40 addi $s0,$s0,1 41 bne $s0,$t0,read1 42 43 move $s0,$0 44 move $s1,$0 45 move $s2,$0 46 read2:mult $s0,$t3 47 mflo $s2 48 add $s2,$s2,$s1 49 li $v0,5 50 syscall 51 move $t4,$v0 52 sll $s2,$s2,2 53 sw $t4,arr2($s2) #t4=b[j][j] 54 55 addi $s1,$s1,1 56 bne $s1,$t3,read2 57 58 move $s1,$0 59 addi $s0,$s0,1 60 bne $s0,$t2,read2 61 62 sub $t4,$t0,$t2 63 addi $t4,$t4,1 #t4=m1-m2+1 64 sub $t5,$t1,$t3 65 addi $t5,$t5,1 #t5=n1-n2+1 66 67 move $s0,$0 #s0=i 68 for_begin1: 69 beq $s0,$t4,for_end1 70 71 move $s1,$0 #s1=j 72 for_begin2: 73 beq $s1,$t5,for_end2 74 move $s2,$0 #s2=temp 75 move $t8,$0 76 move $t9,$0 77 78 move $s3,$0 #s3=m 79 for_begin3: 80 beq $s3,$t2,for_end3 81 82 move $s4,$0 #s4=n 83 for_begin4: 84 beq $s4,$t3,for_end4 85 86 add $t6,$s0,$s3 #t6=i+m 87 slt $s5,$t6,$t0 88 beq $s5,$0,if_end 89 add $t7,$s1,$s4 #t7=j+n 90 slt $s5,$t7,$t1 91 beq $s5,$0,if_end 92 93 mult $t6,$t1 94 mflo $s5 95 add $s5,$s5,$t7 96 sll $s5,$s5,2 97 lw $s6,arr1($s5) #s6=a[i+m][j+n] 98 99 mult $s3,$t3 100 mflo $s5 101 add $s5,$s5,$s4 102 sll $s5,$s5,2 103 lw $s7,arr2($s5) #s7=b[m][n] 104 105 mthi $t8 106 mtlo $t9 107 madd $s6,$s7 108 mfhi $t8 109 mflo $t9 110 111 if_end: 112 addi $s4,$s4,1 113 j for_begin4 114 for_end4: 115 mult $s0,$t5 116 mflo $s5 117 add $s5,$s5,$s1 118 sll $s5,$s5,2 119 sw $t8,arrhi($s5) #hi[i][j]=temphi 120 sw $t9,arrlo($s5) #lo[i][j]=templo 121 122 addi $s3,$s3,1 123 j for_begin3 124 for_end3: 125 nop 126 127 addi $s1,$s1,1 128 j for_begin2 129 for_end2: 130 nop 131 addi $s0,$s0,1 132 j for_begin1 133 for_end1: 134 nop 135 136 move $s0,$0 137 for_begin5: 138 beq $s0,$t4,for_end5 139 140 move $s1,$0 141 for_begin6: 142 beq $s1,$t5,for_end6 143 144 mult $s0,$t5 145 mflo $s2 146 add $s2,$s2,$s1 147 sll $s2,$s2,2 148 lw $a0,arrhi($s2) 149 li $v0,35 150 syscall 151 lw $a0,arrlo($s2) 152 li $v0,35 153 syscall 154 la $a0,space 155 li $v0,4 156 syscall 157 158 addi $s1,$s1,1 159 j for_begin6 160 for_end6: 161 la $a0,line 162 li $v0,4 163 syscall 164 165 addi $s0,$s0,1 166 j for_begin5 167 for_end5: 168 li $v0,10 169 syscall
标签:读取 严格 lang 需要 pre 元素 任务 set word
原文地址:https://www.cnblogs.com/tuoniao/p/10348679.html