Using the assembly language MIPS please help implement this. The shell to use fo
ID: 3876582 • Letter: U
Question
Using the assembly language MIPS please help implement this. The shell to use fo this assignment is below.
# Student Name:
# Date:
# This program computes the similarity count for the two arrays Patch1
# and Patch2 and stores it at the memory location labeled Similarity.
# The similarity count is the number of times each pair of corresponding
# pixels in the two arrays is within an epsilon (5) of each other.
.data
# DO NOT change the following three labels (you may change the initial values):
Patch1: .word 1, 14, 9, 10, 11, 6, 56, 60, 78, 100, 4, 5, 0, 3, 5, 9
Patch2: .word 1, 18, 7, 16, 12, 1, 68, 49, 70, 826, 2, 9, 9, 9, 9, 9
Similarity: .alloc 1
.text
# write your code here...
jr $31 # return to OS
The shell program has two integer arrays declared and initialized as the global variables Patchl and Patch2. Each array contains 16 unsigned integers, representing a set of pixel values in a region of an image. Your program will compute the following measure of how similar the two regions are: compare each pair of corresponding pixels (i.e., for each index i, compare Patch! [i] to Patch2 [i]) and count the number of times they are within an epsilon = 5 of each other (i.e., their difference is less than 5). Your program should print out the similarity count (Similarity) using the print statement in the shell code. Be sure to try multiple test cases, but do not change the declaration of the global variables (you should change only their initial values, such as the pixel values in the two arrays to create new test cases). ECE 2035 Homework 1 Fall 2017 Example Patch![] = Patch! [ ] = Similarity {1, 14, 9, 10, 11, 6, 56, 60, 78, 100, {1, 18, 7, 16, 12, 1, 68, 49, 70, 826, = 1+1+1+0+1+0+0+0+0+0+1+1+0+0+1+1-8 9} 9} 4, 5, 0, 3, 5, 2, 9, 9, 9, 9,Explanation / Answer
Given below is the completed MIPS code as specified in the question. In order to display the result , added a new string "Similarity = " in the .data section.
Hope it helps. If it does, please don't forget to rate the answer. Thank you very much.
# Student Name:
# Date:
# This program computes the similarity count for the two arrays Patch1
# and Patch2 and stores it at the memory location labeled Similarity.
# The similarity count is the number of times each pair of corresponding
# pixels in the two arrays is within an epsilon (5) of each other.
.data
# DO NOT change the following three labels (you may change the initial values):
Patch1: .word 1, 14, 9, 10, 11, 6, 56, 60, 78, 100, 4, 5, 0, 3, 5, 9
Patch2: .word 1, 18, 7, 16, 12, 1, 68, 49, 70, 826, 2, 9, 9, 9, 9, 9
Similarity: .alloc 1
message : .asciiz " Similarity = "
.text
# write your code here...
li $t0, 0 #counter for similarity
la $t1, Patch1 #base addreess of Patch1
la $t2, Patch2 #base address of Patch2
li $t3, 0 #index of array
li $t4, 5 # value of epsilon
loop1:
bge $t3, 16, end_loop1 #if index is >= 16, stop looping
lw $t5, ($t1) #get current value from Patch1
lw $t6, ($t2) #get current value from Patch2
sub $t5, $t5, $t6 # find the difference t5 = t5 - t6
#convert to absolute value if difference is -ve
bgez $t5, compare #difference is +ve, so simply go to comparison
sub $t5, $zero, $t5 #difference is -ve, change it to +ve
compare:
bge $t5, $t4, next_loc #if difference is >= epsilon, don't increment similarity, just move on to next loc
addi $t0, $t0, 1 #increment similarity
next_loc:
addi $t3, $t3, 1 #increment index
addi $t1, $t1, 4 #get next location in Patch1, move by 4 bytes since its an int array
addi $t2, $t2, 4 #get next location in Patch2, move by 4 bytes since its an int array
b loop1
end_loop1:
sb $t0, Similarity
#display the similarity
li $v0, 4
la $a0, message
syscall
#display the int value from $t0
li $v0, 1
move $a0, $t0
syscall
jr $31 # return to OS
output
Similarity = 8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.