Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Sum of Absolute Differences Algorithm
- #
- # Authors:
- # X Y, Z Q
- #
- #
- .text
- main:
- # Initializing data in memory...
- # Store in $s0 the address of the first element in memory
- # lui sets the upper 16 bits of thte specified register
- # ori the lower ones
- # (to be precise, lui also sets the lower 16 bits to 0, ori ORs it with the given immediate)
- # TODO1: initilize the rest of the memory.
- lui $s0, 0x0000 # Address of first element in the vector
- ori $s0, 0x0000
- addi $t0, $0, 5 # left_image[0]
- sw $t0, 0($s0)
- addi $t0, $0, 16 # left_image[1]
- sw $t0, 4($s0)
- addi $t0, $0, 7 # left_image[2]
- sw $t0, 8($s0)
- addi $t0, $0, 1 # left_image[3]
- sw $t0, 12($s0)
- addi $t0, $0, 1 # left_image[4]
- sw $t0, 16($s0)
- addi $t0, $0, 13 # left_image[5]
- sw $t0, 20($s0)
- addi $t0, $0, 2 # left_image[6]
- sw $t0, 24($s0)
- addi $t0, $0, 8 # left_image[7]
- sw $t0, 28($s0)
- addi $t0, $0, 10 # left_image[8]
- sw $t0, 32($s0)
- addi $t0, $0, 4 # right_image[0]
- sw $t0, 36($s0)
- addi $t0, $0, 15 # right_image[1]
- sw $t0, 40($s0)
- addi $t0, $0, 8 # right_image[2]
- sw $t0, 44($s0)
- addi $t0, $0, 0 # right_image[3]
- sw $t0, 48($s0)
- addi $t0, $0, 2 # right_image[4]
- sw $t0, 52($s0)
- addi $t0, $0, 12 # right_image[5]
- sw $t0, 56($s0)
- addi $t0, $0, 3 # right_image[6]
- sw $t0, 60($s0)
- addi $t0, $0, 7 # right_image[7]
- sw $t0, 64($s0)
- addi $t0, $0, 11 # right_image[8]
- sw $t0, 68($s0)
- # .....
- # TODO4: Loop over the elements of left_image and right_image
- addi $t5, $0, 0 # $s1 = i = 0
- addi $t6, $0, 9 # $s2 = image_size = 9
- j loop
- loop:
- # Check if we have traverse all the elements
- # of the loop. If so, jump to end_loop:
- # ....
- # Load left_image{i} and put the value in the corresponding register
- # before doing the function call
- # ....
- # Load right_image{i} and put the value in the corresponding register
- # ....
- # Call abs_diff
- j abs_diff
- # ....
- #Store the returned value in sad_array[i]
- # ....
- # Increment variable i and repeat loop:
- # ...
- end_loop:
- #TODO5: Call recursive_sum and store the result in $t2
- #Calculate the base address of sad_array (first argument
- #of the function call)and store in the corresponding register
- j recursive_sum
- # ...
- # Prepare the second argument of the function call: the size of the array
- #.....
- # Call to funtion
- # ....
- #Store the returned value in $t2
- # .....
- end:
- j end # Infinite loop at the end of the program.
- # TODO2: Implement the abs_diff routine here, or use the one provided
- abs_diff:
- lw $t0, 0($s0)
- lw $t1, 36($s0)
- sub $t2, $t0, $t1
- abs $t2, $t2
- sw $t2, 72($s0) #0
- lw $t0, 4($s0)
- lw $t1, 40($s0)
- sub $t2, $t0, $t1
- abs $t2, $t2
- sw $t2, 76($s0) #1
- lw $t0, 8($s0)
- lw $t1, 44($s0)
- sub $t2, $t0, $t1
- abs $t2, $t2
- sw $t2, 80($s0) #2
- lw $t0, 12($s0)
- lw $t1, 48($s0)
- sub $t2, $t0, $t1
- abs $t2, $t2
- sw $t2, 84($s0) #3
- lw $t0, 16($s0)
- lw $t1, 52($s0)
- sub $t2, $t0, $t1
- abs $t2, $t2
- sw $t2, 88($s0) #4
- lw $t0, 20($s0)
- lw $t1, 56($s0)
- sub $t2, $t0, $t1
- abs $t2, $t2
- sw $t2, 92($s0) #5
- lw $t0, 24($s0)
- lw $t1, 60($s0)
- sub $t2, $t0, $t1
- abs $t2, $t2
- sw $t2, 96($s0) #6
- lw $t0, 28($s0)
- lw $t1, 64($s0)
- sub $t2, $t0, $t1
- abs $t2, $t2
- sw $t2, 100($s0) #7
- lw $t0, 32($s0)
- lw $t1, 68($s0)
- sub $t2, $t0, $t1
- abs $t2, $t2
- sw $t2, 104($s0) #8
- # TODO3: Implement the recursive_sum routine here, or use the one provided
- recursive_sum:
- addi $sp, $sp, -8 # Adjust sp
- add $t0, $t0, $t6 #Iniciar el contador
- sw $ra, 4($sp) # Save return
- lw $t1, 72($s0) #Inicio del vector SAD
- lw $t2, 0($0)
- Q: beqz $t0, out
- REC:
- add $t2, $t2, $t1
- lw $t1, 4($t1)
- subi $t0, $t0, 1
- j Q
- out:
- jr $ra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement