Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am doing this project that picks the top color of an array of numbers from 1 t

ID: 3674979 • Letter: I

Question

I am doing this project that picks the top color of an array of numbers from 1 to 7. I have this code done and it works almost all times but I think sometimes gets wrong. We are using MISASIM that works with MIPS, but is limited to the instructions that I uploaded with the files. I would like to know how using that code I can make it faster and solve the problem that makes sometimes give me an error. Thank you

# T o p o f P i l e
#
#
# This routine finds the color of the part on top of a pile.
#
# <3/5/2016> <>


# $2 - answer
# $5 - north pixel color
# $6 - east pixel color
# $7 - south pixel color
# $8 - west pixel color
# $9 - current address
# $10 - temp value
# $12 - current Nums address
# $14 - number 7
# $16
# $17
# $18

.data
Array: .alloc   1024
Nums:   .word 50462976, 117835012       # array of color values

.text

TopOfPile:   addi   $1, $0, Array       # point to array base
           swi   545                       # generate pile
           addi $2, $0, 1 # always guess the first color

Start:       addi $11, $0, Nums       # base address of Nums
           addi $3, $0, 2048       # pointer
           addi $13, $0, 0           # counter of overlaps
           addi $14, $0, 6           # value of 7
           addi $15, $0, 4031        # value of 4031
          
Loop1:       lbu $4, Array($3)        # current color
           addu $9, $1, $3
          
           beq $4, $0, Continue
          
           addu $2, $0, $3          
           #swi 547                   # highlights current pixel
          
           addi $10, $9, -64
           lbu $5, 0($10) # north pixel color
           beq $5, $0, Continue
           addi $10, $9, -1
           lbu $6, 0($10) # west pixel color
           beq $6, $0, Continue
          
           lbu $12, Nums($5)
           beq $12, $0, Continue
          
           addi $10, $9, 64
           lbu $7, 0($10) # south pixel color
           addi $10, $9, 1
           lbu $8, 0($10) # east pixel color
           beq $5, $6, Continue
           bne $5, $7, Continue
           bne $4, $6, Case2
          
Case1:       bne $4, $8, Continue # Case 1 is checking for the first kind of intersection
           lbu $12, Nums($5)
           beq $12, $0, Continue
           sb $0, Nums($5)           # deletes color from array
           lbu $2, Nums($4)       # loads color to answer $2
           addi $13, $13, 1
           beq $13, $14, End
          
Continue:   bne $3, $15, Continue2
           addi $3, $0, 64
           j Loop1
          
Continue2:   addi $3, $3, 1
           j Loop1
          
Case2:       bne $5, $4, Continue # Case 2 checks for the second kind of intersection
           bne $7, $4, Continue
           lbu $12, Nums($8)
           beq $12, $0, Continue
           sb $0, Nums($6)       # deletes color from array
           addi $13, $13, 1
           lbu $2, Nums($4)       # loads color to answer $2
           beq $13, $14, End  
           j Continue   # lbu $2, Nums($4)


End:   swi   546           # submit answer and check
       jr   $31           # return to caller

Top of Pile: This project explores a programming problem that arises in many different robotics applications. In a manufacturing setting, a robotic arm may need to pick up parts from a pile and use them to assemble something such as an automobile. To plan the robotic arm's movements, an overhead camera may be positioned over a pile of parts. In this assignment, we will focus on determining which color part is on top of the pile. (This may be important in finding a particular component and uncovering it so it can be used.) We would like this task to be performed in real- time, so the computational and storage requirements must be kept to a minimum We are also concerned with the functional correctness of the algorithms used (i.e, getting the correct answer), since picking the wrong top part could lead to extra work for the robot or worse a mal function if the pieces get tangled. Figure. Pile of Parts (test case: pilel-ans6.txt) Description: Consider a pile composed of seven parts viewed from above on a 64x64 image ar- ray of cells each cel is one of eight colors (black-0, pink-1, red 2, green-3, bluc-4, orange 5 yellow 6, skyblue 7). Each part has a unique color. There will be exactly one part that is on top of the pile. All other parts will be overlapping at least one part. Figure 1 shows an example pile image. In this example, the yellow part is on top. The answer is 6: the color yellow 0 1 2 3 4 5 67 Figure 2: Color Palette Each part is composed of horizontal and vertical lines all of the same color. Not all parts have the same number of horizontal or vertical lines. All horizontal lines in a part have the same length which ranges from 25 to 45 pixels. Similarly, all vertical lines in a part have the same length in the same range. A part's horizontal line length is not necessarily the same as its vertical line length. No parallel lines are adjacent to any other lines in the same part or in other parts. Each row (column) has at most one horizontal (vertical) line. No horizontal lines occlude (over-

Explanation / Answer

In case1 , case2, we are using "sb statement" will handles signed integers ... , but using sbu statement, we can handle for unsigned integers .. sometimes if we have any negative numbers, then it will fail. So it is better to make sbu statement.

Case1:       bne $4, $8, Continue # Case 1 is checking for the first kind of intersection
           lbu $12, Nums($5)
           beq $12, $0, Continue
           sbu $0, Nums($5)           # deletes color from array
           lbu $2, Nums($4)       # loads color to answer $2
           addi $13, $13, 1
           beq $13, $14, End

Remaining code, seemed to be correct and working fine.