Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- transform:
- ############################### Part 2: your code begins here ##
- #T1 COUNTS X(inner) T0 COUNTS Y(row)
- li $t0, 0 #counter that will exit out of row loop (y)
- countYLoop:
- beq $t0, $a3, exitYLoop #potential for error, exit entire loop if the final element is reached
- li $t1, 0 #resets the x counter once dim(end of array row) is reached
- countXLoop:
- beq $t1, $a3, exitXLoop #branches once the end of the end of the array row is reached
- #calc x0
- lbu $t2, 0($a2) #Gives M00 of transformation matrix ASSUMING INT IS 4 BYTES
- mul $t2, $t2, $t1
- lbu $t3, 4($a2) #gives M01 of transformation matrix ASSUMING INT IS 4 BYTES
- mul $t3, $t3, $t0
- add $t2, $t2, $t3
- lbu $t3, 8($a2) #M02 assuming 4 bytes per element
- add $t2, $t3, $t2 # X0 IS STORED HERE
- #calc y0
- lbu $t3, 12($a2)
- mul $t3, $t3, $t1
- lbu $t4, 16($a2)
- mul $t4, $t4, $t0
- add $t3, $t3, $t4
- lbu $t5, 20($a2)
- add $t3, $t5, $t3 # y0 IS STORED HERE
- #check bounds
- bge $t2, $a3, outOfBounds
- blt $t2, $zero, outOfBounds
- bge $t3, $a3, outOfBounds
- blt $t3, $zero, outOfBounds
- #if youre in this code block, youre in bounds
- mul $t4, $t3, $a3 #y0 * dim
- add $t4, $t4, $t2 # OFFSET OF x0 y0 IS STORED IN T4
- add $a0, $a0, $t4 #SHIFTS THE ADDRESS TO THE OFFSET CALCULATED IN THE ABOVE STEP
- lbu $t5, 0($a0) #HOLDS DATA OF INPUT ARRAY OFSETTED BY T4 in T5
- #sub $a0, $a0, $t4 #RESET ADDRESS A0 TO POINT TO THE BEGINNING OF THE ARRAY
- mul $t4, $t0, $a3 #CALCULATE OFFSET FOR THE OUTPUT MATRIX AND STORE IN T4
- add $t4, $t4, $t1
- add $a1, $a1, $t4 #OFFSETS OUTPUT MATRIX TO X AND Y
- sb $t5, 0($a1) #STORES CONTENTS OF input(x0,y0) TO T5
- #sub $a1, $a1, $t4 #Reset address A1 to point to the beginning of the output array
- addi $t1, $t1, 1 #update col(x) counter
- j countXLoop
- exitXLoop:
- addi $t0, $t0, 1 #INCRE X COUNTER
- j countYLoop
- exitYLoop:
- #out of bounds condition: store 0 in offsetted index
- outOfBounds:
- #calculate offset for X and Y COUNTERS
- mul $t4, $t0, $a3
- add $t4, $t4, $t1
- add $a1, $a1, $t4 #ADD OFFSET (stored in t4) TO OUTOUT ADDRESS
- sb $zero, 0($a1)
- #sub $a1, $a1, $t4 #RESET A1 TO POINT AT THE BEGINNING OF THE ARRAY
- addi $t0, $t0, 1 #update col(x) counter
- j countXLoop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement