Advertisement
JosepRivaille

Pràctica 3 - EC - S3 - FIB

Oct 24th, 2015
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. # PRACTICA 3 #######################
  2.  
  3. ## 3.1 ##
  4.  
  5. .data
  6. mat1: .space 5*6*4 # NF*NC*NB (int = 4 bytes)
  7. mat2: .space 3*5 # NB = 1 (char = 1 byte)
  8. .align
  9. mat3: .space 2*2*8 # NB = 8 (long long = 8 bytes)
  10. mat4: .word 2,3,1,2,4,3
  11.  
  12.  
  13. ## 3.2 ##
  14.  
  15. # @mat[i][j] = @mat + (i*NC + j) * NB
  16.  
  17. @mat1[4][3] = @mat1 + (4*6 + 3)*4
  18. @mat2[2][4] = @mat2 + 2*5 + 4
  19. @mat3[1][0] = @mat3 + 1*2*8
  20. @mat4[0][2] = @mat4 + 2*4
  21.  
  22.  
  23. ## s3b.s | 3.4 - 3.5 ##
  24.  
  25. .data
  26. mat1: .space 120 # 120 = 5*6*4
  27. mat4: .word 2,3,1,2,4,3
  28. col: .word 2
  29.  
  30. .text
  31. .globl main
  32.  
  33. main: addiu $sp, $sp, -16 # Guardem adreça retorn
  34. sw $ra, 0($sp)
  35. sw $s0, 4($sp)
  36. sw $s1, 8($sp)
  37. sw $s2, 12($sp)
  38.  
  39. la $s0, mat1+108 # 108 = (4*6 + 3) *4
  40. # $s0 = &mat1[4][3]
  41. la $s1, mat4 # $s1 = &mat4[0][0]
  42. addiu $s2, $s1, 8 # 8 = 2*4
  43. # $s2 = mat4[0][2]
  44. move $a0, $s1
  45. move $a1, $s2
  46. la $a2, col
  47.  
  48. lw $a1, 0($a1)
  49. lw $a2, 0($a2)
  50.  
  51. jal subr # Crida subr 1
  52. sw $v0, 0($s0) # mat1[4][3] = subr(mat4, mat4[0][2], col)
  53.  
  54. la $s0, mat1 # $t0 = &mat1[0][0]
  55. addiu $a1, $zero, 1
  56. addiu $a2, $zero, 1
  57.  
  58. jal subr # Crida subr 2
  59. sw $v0, 0($s0) # mat1[0][0] = subr(mat4, 1, 1)
  60.  
  61. lw $ra, 0($sp) # Carreguem adreça retorn
  62. lw $s0, 4($sp)
  63. lw $s1, 8($sp)
  64. lw $s2, 12($sp)
  65. addiu $sp, $sp, 16
  66. jr $ra
  67.  
  68.  
  69. subr: addiu $sp, $sp, -16 # Copia seguretat paràmetres
  70. sw $a0, 0($sp)
  71. sw $a1, 4($sp)
  72. sw $a2, 8($sp)
  73. sw $ra, 12($sp)
  74.  
  75. la $t0, mat1 + 20 # $t0 = @mat1[0][5]
  76. li $t1, 24 # 6*4
  77. mult $t1, $a2 # col*24
  78. mflo $t1
  79. addu $t0, $t0, $t1 # $t0 = @mat1[j][5]
  80.  
  81. move $t2, $a0
  82. li $t1, 3
  83. mult $a1, $t1
  84. mflo $t1 # i*3
  85. addu $t1, $t1, $a2 # i*3 + j
  86. sll $t1, $t1, 2 # *4
  87. addu $t2, $t2, $t1 # $t2 = @x[i][j]
  88. lw $t1, 0($t2)
  89. sw $t1, 0($t0) # @mat1[j][5] = x[i][j];
  90.  
  91. move $v0, $a1
  92.  
  93. lw $a0, 0($sp)
  94. lw $a1, 4($sp)
  95. lw $a2, 8($sp)
  96. lw $ra, 12($sp)
  97. addiu $sp, $sp, 16
  98. jr $ra
  99.  
  100.  
  101.  
  102.  
  103. ## 3.5 ##
  104.  
  105. @mat[i][2] = mat + (i*6 + 2)*4 = mat + i*24 + 8
  106.  
  107. stride = @mat[i+1][2] - @mat[i][2] = [mat + ((i+1)*6 + 2)*4] - (mat + i*24 + 8)
  108. mat + (i+1)*24 + 8 - mat - i*24 - 8
  109. mat - mat + i*24 - i*24 + 24 + 8 - 8
  110. stride = 24bytes
  111.  
  112.  
  113. ## s3c.s | 3.6 ##
  114.  
  115. .data
  116. mat: .word 0,0,2,0,0,0
  117. .word 0,0,4,0,0,0
  118. .word 0,0,6,0,0,0
  119. .word 0,0,8,0,0,0
  120. result: .space 4
  121.  
  122. .text
  123. .globl main
  124.  
  125. main: addiu $sp, $sp, -8
  126. sw $ra, 0($sp)
  127. sw $s0, 4($sp)
  128.  
  129. la $s0, result
  130. la $a0, mat
  131. jal suma_col
  132. sw $v0, 0($s0) # result = suma_col(mat);
  133.  
  134. lw $ra, 0($sp) # carreguem adreça retorn
  135. lw $s0, 4($sp)
  136. addiu $sp, $sp, 8
  137. jr $ra
  138.  
  139. suma_col:
  140. addiu $sp, $sp, -4
  141. sw $a0, 0($sp)
  142.  
  143. move $t0, $zero # i = 0
  144. move $t1, $zero # suma = 0
  145. addiu $t2, $a0, 8 # $t1 = & mat+ 2*4 Inicialitzar punter
  146. li $t3, 4
  147.  
  148. for: lw $t4, 0($t2) # $t1 = mat[x][y]
  149. addu $t1, $t1, $t4
  150. addiu $t2, $t2, 24 # 24 = 6*4
  151. addiu $t0, $t0, 1
  152. blt $t0, $t3, for
  153.  
  154. move $v0, $t1
  155.  
  156. lw $a0, 0($sp)
  157. addiu $sp, $sp, 4
  158. jr $ra
  159.  
  160.  
  161. ## JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement