Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Write a MIPS assembler program to find the how many elements # are in a repeating pattern. Create a binary bit string of #

# Write a MIPS assembler program to find the how many elements # are in a repeating pattern. Create a binary bit string of # 1 if the value is larger, or 0 if the value is smaller. # Rotate the up-down pattern one position at a time and XOR # it with the original up-down pattern. If the XOR is zero # or a small number of 1 bits, you've found how often the # pattern repeats. # # SAMPLE OUTPUT: # Binary Pattern: 00000000000000001000100010001000 # # rotate= 00000000000000000001000100010001 xor= 00000000000000001001100110011001 sum= 8 # rotate= 00000000000000000010001000100010 xor= 00000000000000001010101010101010 sum= 8 # rotate= 00000000000000000100010001000100 xor= 00000000000000001100110011001100 sum= 8 # rotate= 00000000000000001000100010001000 xor= 00000000000000000000000000000000 sum= 0 # rotate= 00000000000000000001000100010001 xor= 00000000000000001001100110011001 sum= 8 # rotate= 00000000000000000010001000100010 xor= 00000000000000001010101010101010 sum= 8 # rotate= 00000000000000000100010001000100 xor= 00000000000000001100110011001100 sum= 8 # rotate= 00000000000000001000100010001000 xor= 00000000000000000000000000000000 sum= 0 # rotate= 00000000000000000001000100010001 xor= 00000000000000001001100110011001 sum= 8 # rotate= 00000000000000000010001000100010 xor= 00000000000000001010101010101010 sum= 8 # rotate= 00000000000000000100010001000100 xor= 00000000000000001100110011001100 sum= 8 # rotate= 00000000000000001000100010001000 xor= 00000000000000000000000000000000 sum= 0 # rotate= 00000000000000000001000100010001 xor= 00000000000000001001100110011001 sum= 8 # rotate= 00000000000000000010001000100010 xor= 00000000000000001010101010101010 sum= 8 # rotate= 00000000000000000100010001000100 xor= 00000000000000001100110011001100 sum= 8 # rotate= 00000000000000001000100010001000 xor= 00000000000000000000000000000000 sum= 0 # # Pattern repeats every 4 # # ---------------------------------------------------------- # C++ Equivalent # ---------------------------------------------------------- #include #include #include #using namespace std; # #// ml06XorPattern C++ Equivalent # #;int main() #{ # const int SIZE = 16; # unsigned short sequence[] = { 7, 5, 3, 2, 8, 6, 3, 2, 7, 6, 4, 1, 7, 4, 4, 3 }; # unsigned short updown = 0; # # //Create the up-down pattern # unsigned short last = 0; # for (int x = 0; x < SIZE; x++) { # updown = (updown << 1); # updown += (sequence[x] > last) ? 1 : 0; # last = sequence[x]; # } # bitset<16> binary{ updown }; # cout << "Binary Pattern: " << binary << endl <> 1; # rotate = rotate | (bit0 << SIZE-1); //put low bit in position 11 # bitset<16> rotateBin{ rotate }; # cout << x << "\trotate= " << rotateBin; # # xorResults[x] = updown ^ rotate; //XOR # bitset<16> xorBin{ xorResults[x] }; # cout << "\txor= " << xorBin; # # int sum = 0; # for (int i = 0; i < SIZE; i++) # if (xorResults[x] & (1 << i)) sum++; //sum 1-bits # cout << "\tsum= " << sum << endl; # xorResults[x] = sum; # } # # // Find the smallest sum # int answer = SIZE-1; # last = 99; # for (int x = SIZE-1; x > 0; x--) { # if (xorResults[x] <= last) { # answer = x; # last = xorResults[x]; # } # } # cout << " Pattern repeats every " << answer << endl; # cin.get(); cin.get(); # return 0; #} .data .eqv SYS_PRINT_WORD 1 #word, byte, character .eqv SYS_PRINT_FLOAT 2 #float .eqv SYS_PRINT_DOUBLE 3 #double .eqv SYS_PRINT_TEXT 4 #text (zero terminated) .eqv SYS_INPUT_WORD 5 #input word .eqv SYS_INPUT_FLOAT 6 #input float .eqv SYS_PRINT_BIN 35 #print binary .eqv SYS_EXIT 10 #terminate

# //declare variables .eqv SIZE 32 sequence: .half 7, 5, 3, 2, 8, 6, 3, 2, 7, 6, 4, 1, 7, 5, 4, 3 # sequence: .half 7, 5, 3, 8, 6, 3, 7, 6, 4, 7, 5, 4, 8, 6, 3, 0 # sequence: .half 7, 6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 7, 6, 5, 4 xorResults: .space SIZE #16 halfwords updown: .half 0 last: .half 0 rotate: .half 0 xor: .half 0 bit0: .half 0 endl: .asciiz " " endl2: .asciiz " " txPattern: .asciiz " Binary Pattern: " txRotate: .asciiz "\trotate= " txXor: .asciiz "\txor= " txSum: .asciiz "\tsum= " txAnswer: .asciiz " Pattern repeats every " .text .globl main main:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago