两个浮点2-d数组的乘法

时间:2012-09-23 18:53:07

标签: mips

我有两个3x3浮点数组。我将它们存储为两个1D数组,并编写以下代码将它们相乘(这里,s3是输出矩阵): -  MULTIP1:       li $ t8,4                             #$ s7具有数组s2的地址,$ s4具有数组arr的地址       la $ t9,s3       li $ t1,0       li $ t2,1       li $ t3,0       li $ t4,1

LOOP1:
 beq $t4,$t8,MULTIP2    #multip2 is the next segment of program
 li $t2,1
ENTER1:
beq $t2,$t8,UP1
li $t0,1
LOOP2:
  beq $t0,$t8,UP2
ENTER2:
  lwc1 $f22,0($s7)
  lwc1 $f24,0($s4)
  mul.s $f8,$f22,$f24
  add.s $f10,$f10,$f8
  swc1 $f10,0($t9)

  addi $s7,$s7,4
  addi $s4,$s4,12
  addi $t0,$t0,1
  j LOOP2
UP2:
  l.s  $f10,zero
  addi $t9,$t9,4
  addi $t1,$t1,4     #update column of second matrix
  la $s7,s2
  add $s7,$s7,$t3
  la $s4,arr
  add $s4,$s4,$t1
  addi $t2,$t2,1
  j ENTER1
UP1:

  addi $t3,$t3,12
  la   $s7,s2
  add  $s7,$s7,$t3  #update row of first matrix
  la   $s4,arr
  addi $t4,$t4,1
  j LOOP1

这段代码只给出了预期输出矩阵的第一行......剩下的就搞砸了....请帮忙!!!

1 个答案:

答案 0 :(得分:0)

  • 这不仅仅是两个3x3矩阵的点积吗?
  • 2 3x3矩阵的点积导致3x3矩阵
  • 假设2个3x3矩阵:A和B。
  • Matrix C C = AB的产品如下:

    A = [a11,a12,a13]     [a21,a22,a23]     [a31,a32,a33]

    B = [b11,b12,b13]     [b21,b22,b23]     [b31,b32,b33]

    C = [c11,c12,c13]     [c21,c22,c23]     [c31,c32,c33]

    c11 = a11 * b11 + a12 * b21 + a13 * b31 c12 = a11 * b12 + a12 * b22 + a13 * b23 c13 = a11 * b13 + a12 * b23 + a13 * b32 c21 = a21 * b11 + a22 * b21 + a23 * b31 c22 = a21 * b12 + a22 * b22 + a23 * b32 c23 = a21 * b13 + a22 * b23 + a23 * b33 c31 = a31 * b11 + a32 * b21 + a33 * b31 c32 = a31 * b12 + b32 * b22 + a33 * b32 c33 = a31 * b13 + a32 * b23 + a33 * b33