Advertisement
Guest User

part 2

a guest
Dec 9th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. transform:
  2. ############################### Part 2: your code begins here ##
  3.  
  4.  
  5.  
  6. #T1 COUNTS X(inner) T0 COUNTS Y(row)
  7.  
  8. li $t0, 0 #counter that will exit out of row loop (y)
  9.  
  10. countYLoop:
  11. beq $t0, $a3, exitYLoop #potential for error, exit entire loop if the final element is reached
  12. li $t1, 0 #resets the x counter once dim(end of array row) is reached
  13.  
  14. countXLoop:
  15. beq $t1, $a3, exitXLoop #branches once the end of the end of the array row is reached
  16.  
  17. #calc x0
  18. lbu $t2, 0($a2) #Gives M00 of transformation matrix ASSUMING INT IS 4 BYTES
  19. mul $t2, $t2, $t1
  20.  
  21. lbu $t3, 4($a2) #gives M01 of transformation matrix ASSUMING INT IS 4 BYTES
  22. mul $t3, $t3, $t0
  23.  
  24. add $t2, $t2, $t3
  25. lbu $t3, 8($a2) #M02 assuming 4 bytes per element
  26.  
  27. add $t2, $t3, $t2 # X0 IS STORED HERE
  28.  
  29.  
  30. #calc y0
  31. lbu $t3, 12($a2)
  32. mul $t3, $t3, $t1
  33.  
  34. lbu $t4, 16($a2)
  35. mul $t4, $t4, $t0
  36.  
  37. add $t3, $t3, $t4
  38.  
  39. lbu $t5, 20($a2)
  40.  
  41. add $t3, $t5, $t3 # y0 IS STORED HERE
  42.  
  43.  
  44.  
  45.  
  46. #check bounds
  47. bge $t2, $a3, outOfBounds
  48. blt $t2, $zero, outOfBounds
  49. bge $t3, $a3, outOfBounds
  50. blt $t3, $zero, outOfBounds
  51.  
  52. #if youre in this code block, youre in bounds
  53. mul $t4, $t3, $a3 #y0 * dim
  54. add $t4, $t4, $t2 # OFFSET OF x0 y0 IS STORED IN T4
  55.  
  56. add $a0, $a0, $t4 #SHIFTS THE ADDRESS TO THE OFFSET CALCULATED IN THE ABOVE STEP
  57. lbu $t5, 0($a0) #HOLDS DATA OF INPUT ARRAY OFSETTED BY T4 in T5
  58. #sub $a0, $a0, $t4 #RESET ADDRESS A0 TO POINT TO THE BEGINNING OF THE ARRAY
  59.  
  60. mul $t4, $t0, $a3 #CALCULATE OFFSET FOR THE OUTPUT MATRIX AND STORE IN T4
  61. add $t4, $t4, $t1
  62. add $a1, $a1, $t4 #OFFSETS OUTPUT MATRIX TO X AND Y
  63. sb $t5, 0($a1) #STORES CONTENTS OF input(x0,y0) TO T5
  64. #sub $a1, $a1, $t4 #Reset address A1 to point to the beginning of the output array
  65.  
  66.  
  67. addi $t1, $t1, 1 #update col(x) counter
  68. j countXLoop
  69.  
  70. exitXLoop:
  71.  
  72. addi $t0, $t0, 1 #INCRE X COUNTER
  73.  
  74. j countYLoop
  75.  
  76. exitYLoop:
  77.  
  78.  
  79. #out of bounds condition: store 0 in offsetted index
  80. outOfBounds:
  81. #calculate offset for X and Y COUNTERS
  82. mul $t4, $t0, $a3
  83. add $t4, $t4, $t1
  84. add $a1, $a1, $t4 #ADD OFFSET (stored in t4) TO OUTOUT ADDRESS
  85. sb $zero, 0($a1)
  86. #sub $a1, $a1, $t4 #RESET A1 TO POINT AT THE BEGINNING OF THE ARRAY
  87. addi $t0, $t0, 1 #update col(x) counter
  88. j countXLoop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement