Question

Please finish this Assembly code. Modify it to compute the number of elements in the deiiference...

Please finish this Assembly code.

Modify it to compute the number of elements in the deiiference of SetA and SetB (as in HW1-2) and store that number at the memory
location labeled DifferenceSize. Again, assume that SetA has eight integers and SetB has ten,
and that the two sets are “sets” in that there are no duplicate elements within an individual set but
they may be in any order.

#
# This program determines difference of SetA (always of size 8) and SetB
# (always of size 10) and stores the size of the difference.


# NOTE:
# The program should work on multiple test cases, not just the one provided.
# For full credit, be sure to document your code.

.data
SetA: .word 8, 3, -27, -60, 25, 17, 26, 9
SetB: .word 5, 17, -7, 3, -25, 27, 42, 26, 8, -60
DifferenceSize: .alloc 1

.text      
       # write your code here...

       jr $31              # return to OS

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

Program

#
# This program determines difference of SetA (always of size 8) and SetB
# (always of size 10) and stores the size of the difference.


# NOTE:
# The program should work on multiple test cases, not just the one provided.
# For full credit, be sure to document your code.

.data
SetA: .word 8 3 -27 -60 25 17 26 9
SetB: .word 5 17 -7 3 -25 27 42 26 8 -60
DifferenceSize: .alloc 1

.text    
       #Get the base address of SetA
       addi $t0,$0,0x00000000
       #for difference set count
       addi $s0,$0,0
       #counter for outer loop
       addi $t3,$0,0
#loop to find difference of SetA-SetB
OuterLoop:
      #Get all elements of SetA
      addi $1,$0,8
      beq $1,$t3,Exit
      #Flag variable
      addi $t2,$0,0
      #Get elements from SetA
      lw $t5,0($t0)
      #Base address of SetB
      addi $t1,$0,0x00000020
      #Counter for second loop
      addi $t4,$0,0
#Loop through to get setB values
InnerLoop:
      addi $1,$0,10
      beq $1,$t4,InnerExit
      #Get eleemnts of SetB
      lw $t6,0($t1)
      #compare
      bne $t5,$t6,Inc
      #flag set if found SetA elemnt in SetB
      addi $t2,$t2,1
Inc:
     #Increment SetB address
     addi $t1,$t1,4
     #Increment counter
     addi $t4,$t4,1
     j InnerLoop
InnerExit:
      #check flag set or not
      addi $1,$0,0
      bne $1,$t2,next
      #f not set increment difference counter
      addi $s0,$s0,1
#Increment address of SetA for next element
#Increment outer loop counter
next:
     addi $t0,$t0,4
     addi $t3,$t3,1
     j OuterLoop
#store and display
Exit:
    #Get address of difference size
    la $t7,DifferenceSize
    #store difference size in allocated space
    sw $s0,0($t7)
    #Display store difference size
    addi $v0,$0,1
    lw $a0,0($t7)
    syscall
     jr $31              # return to OS

-------------------------------------------------------

Output

3

-------------------

Note:-

I am using MARS 4.5

I assume you want SetA-SetB count

Add a comment
Know the answer?
Add Answer to:
Please finish this Assembly code. Modify it to compute the number of elements in the deiiference...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last in...

    using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1. Determine the sum of all...

  • E2.15 In assembly code, write a program to count the number of elements in an array...

    E2.15 In assembly code, write a program to count the number of elements in an array that are smaller than 16. The array is stored at memory locations starting from $1010. The array has 30 8-bit unsigned elements. Store the count in the memory location $C001.

  • Can someone solve number 5 using Matlab? In Class Exercises 8-Arrays For the following exercises, assume...

    Can someone solve number 5 using Matlab? In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1....

  • Please in C Language Thank you! The following program source code is incomplete 1 #include <stdio.h> 2 3 // TODO:...

    Please in C Language Thank you! The following program source code is incomplete 1 #include <stdio.h> 2 3 // TODO: 1) Add the typedef here: 5// TODO: 2) Modify the parameter of repeat to add irn the function pointer for the function to be called repeatedly: 8 void repeat (int times) for (int k 0; k < times; ++k) 12 // TODO: 3) Add the call to the function pointer here: 14 15 17 void test (void) 18 printf("Test!\n"); 19...

  • The MIPS assembly program given here is expected to find the sum of elements in array...

    The MIPS assembly program given here is expected to find the sum of elements in array "myArr. Even though the code is syntactically correct, there are four bugs because of which the program is not glving the required output. With the help of the line numbers given identify the bug. Write the line number where you find the bug and give how the correct statement to eliminate the corresponding logical error (10 points partial points given for partial correct answers)...

  • Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine...

    Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine library procedures Objectives: 1. using register indirect addressing 2. passing parameters 3. generating “random” numbers 4. working with arrays Description: Write and test a MASM program to perform the following tasks: 1. Introduce the program. 2. Generate ARRAYSIZE random integers in the range [LO = 10 .. HI = 29], storing them in consecutive elements of an array. ARRAYSIZE should be set to 200....

  • MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random...

    MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...

  • Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here...

    Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here is the code, partially commented. .data Matrix: .word 41,45,5, 34,8, 15,16,23,44,48,12,32,18,47,22,8,22 .word 46,40,42,33,13,38,27,6, 29,25,18,40,47,22,26,14,3 .word 7, 48,35,9, 43,38,9, 49,28,25,42,5, 44,10,5, 38,14 .word 46,33,16,6, 13,20,31,1, 8, 17,1, 47,28,46,14,28,7 .word 32,2, 48,25,41,29,14,39,43,46,3, 39,32,49,41,28,46 .word 5, 43,2, 48,13,4, 33,41,32,19,9, 25,30,22,2, 9, 40 .word 14,47,22,18,47,3, 35,44,18,6, 33,22,11,6, 47,50,4 .word 28,34,20,30,18,27,38,5, 26,40,37,23,16,13,37,8,7 .word 48,38,39,12,10,39,23,20,21,20,33,16,24,21,25,3,46 .word 49,38,40,38,13,47,5, 13,4, 13,23,26,12,30,29,29, 3 .word 8, 20,10,13,31,7, 12,41,12,21,28,26,43,14,35,10,19 .word 49,33,25,26,24,29,46,22,7, 5, 15,41,10,31,19,41,27 .word 48,9,...

  • This question has been answered before, but no codes given as the answer were right. please...

    This question has been answered before, but no codes given as the answer were right. please help. In the mathematical theory of sets, a set is defined as a collection of distinct items of the same type. In some programming languages, sets are built-in data types; unfortunately, this is not the case in C++. However, we can simulate a set using a one-dimensional array. Some operations can be performed on sets. We will consider three(3) of them: union, intersection and...

  • 2) Write an assembly program that is algorithmically equivalent to the following C+t code Consider the variables to be 8-bit unsigned integers; you may initialize them to any values 0-255 if you like...

    2) Write an assembly program that is algorithmically equivalent to the following C+t code Consider the variables to be 8-bit unsigned integers; you may initialize them to any values 0-255 if you like for testing purposes 13 int speed, lower, a, b; 14 15 if (speed < 98) { 16 17 if (speed <80) t 18 lower++; 19 20 21 else f 23 24 25 26 else t 27 28 2) Write an assembly program that is algorithmically equivalent to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT