Write this program using Mips programming language Write a function that compute
ID: 3783376 • Letter: W
Question
Write this program using Mips programming language Write a function that computes the next state of a linear feedback shift register (LFSR) given the current state of the LFSR. The LFSR should satisfy the taps given by the following polynomial: x^20 + x^19 + x^16 + x^14 + 1 Your function should take the state as a 32-bit input parameter and return a 32-bit output value. Your main program for the function should call your LFSR function for the following input states and print the output state: Write a new program using your LFSR function from the first problem. Start from state 0x00000001, then run a loop counting all the possible states in the LFSR before it cycles back to 0x00000001. This is shown by the following pseudocode:Explanation / Answer
We talked about linear feedback shift registers (LFSRs) back in the very first lecture. An LFSR is a sequence of bits capable of a discrete step operation that
Shifts the bits one position to the left, and
Replaces the vacated bit by the exclusive or of the bit shifted off and the bit previously at a given tap position in the register.
class LFSR {
public:
LFSR(string seed, int t); // constructor to create LFSR with the given initial seed and tap
string to_string(); // return a string representation of the LFSR's current state
int step(); // simulate one step and return the new bit as 0 or 1
int generate(int k); // simulate k steps and return k-bit integer
private: ... }
Constructor. The constructor takes the initial seed as a string argument whose characters are a sequence of 0s and 1s. The length of the register is the length of the seed. We will generate each new bit by xoring the leftmost bit and the tap bit. The position of the tap bit comes from the constructor argument. For example, the following code should create the LFSR described above.
LFSR lfsr("01101000010", 8);
Destructor. If your constructor dynamically allocates memory, make sure to define a destructor that deallocates it.
String representation. The to_string() function returns a string representation of the LFSR by concatenating the values in the registers. For example,
LFSR lfsr("01101000010", 8);
cout << lfsr.to_string() << endl;
should output
01101000010
Simulate one step. The step() function simulates one step of the LFSR and returns the rightmost bit as an integer (0 or 1). For example,
LFSR lfsr("01101000010", 8);
for (int i = 0; i < 10; i++) {
int bit = lfsr.step();
cout << lfsr.to_string() << " " << bit << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.