Write a function in MIPS Assembly Language 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^15 + 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: 0x00000001 0xdeadbeef 0x200214c8 0x00000000

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a function in MIPS Assembly Language 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^15 + 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:

0x00000001

0xdeadbeef

0x200214c8

0x00000000

Expert Solution
Step 1

Given:

We have to write a function in MIPS Assembly Language 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^15 + x^14 +1

Our function should take the state as a 32-bit input parameter and return a 32-bit output value. Our main program for the function should call our LFSR function for the following input states and print the output state:

0x00000001

0xdeadbeef

0x200214c8

0x00000000

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

The last line of the code, is there something missing on it? The last line says, 

"move $v0, "

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

The output I got is 32768. Then after that line are next three lines of "(null)" with error message "Memory address out of bounds."

This is the updated code that you provided:

 

.data
newline:
    .asciiz "\n"
    .globl main
    .text
main:
    # compute the next state of the LFSR for each input state
    li $a0, 0x00000001
    jal lfsr_next_state
    move $t0, $v0
    li $a0, 0xdeadbeef
    jal lfsr_next_state
    move $t1, $v0
    li $a0, 0x200214c8
    jal lfsr_next_state
    move $t2, $v0
    li $a0, 0x00000000
    jal lfsr_next_state
    move $t3, $v0

    # print the output states
    li $v0, 1  # set system call for printing integer
    move $a0, $t0
    syscall
    la $a0, newline
    li $v0, 4  # set system call for printing string
    syscall
    move $a0, $t1
    syscall
    la $a0, newline
    syscall
    move $a0, $t2
    syscall
    la $a0, newline
    syscall
    move $a0, $t3
    syscall

    # exit the program
    li $v0, 10
    syscall

# Function to compute the next state of an LFSR
# Input parameter: $a0 = current state
# Output: $v0 = next state
lfsr_next_state:
    # Initialize upper mask with 0x8000 and lower mask with 0x0001
    li $t0, 0x8000
    li $t1, 0x0001
    # Initialize result with 0
    li $v0, 0
    # Loop through all 32 bits of the input state
    li $t2, 0
    li $t3, 0
lfsr_loop:
    # Shift the current state to the right
    srl $a0, $a0, 1
    # Get the least significant bit of the current state
    andi $t2, $a0, 1
    # If the least significant bit is 1, XOR with the tap mask
    beq $t2, 1, lfsr_xor
    j lfsr_continue
lfsr_xor:
    xor $a0, $a0, $t0
lfsr_continue:
    # Shift the tap mask to the right
    srl $t0, $t0, 1
    # If the tap mask is zero, reset it to the original mask
    bne $t0, $zero, lfsr_increment
    li $t0, 0x8000
lfsr_increment:
    # Increment the loop counter
    addi $t3, $t3, 1
    # If the loop counter is less than 32, continue the loop
    blt $t3, 32, lfsr_loop
    # Set the result to the current state
    move $v0, $a0
    jr $ra

 

Can you help me fix this code? Thanks

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

This is the follow up question from the previous follow up question. 

The code has to work in QtSpim. My professor wants the class to use the QtSpim. From the updated code, I am still getting error that says "Memory address out of bounds" and negative output. Can you help me fix this. Thanks.

 

.data
newline:
    .asciiz "\n"
    .globl main
    .text
main:
    # compute the next state of the LFSR for each input state
    li $a0, 0x00000001
    jal lfsr_next_state
    move $t0, $v0
    li $a0, 0xdeadbeef
    jal lfsr_next_state
    move $t1, $v0
    li $a0, 0x200214c8
    jal lfsr_next_state
    move $t2, $v0
    li $a0, 0x00000000
    jal lfsr_next_state
    move $t3, $v0

    # print the output states
    li $v0, 1  # set system call for printing integer
    move $a0, $t0
    syscall
    la $a0, newline
    li $v0, 4  # set system call for printing string
    syscall
    move $a0, $t1
    syscall
    la $a0, newline
    syscall
    move $a0, $t2
    syscall
    la $a0, newline
    syscall
    move $a0, $t3
    syscall

    # exit the program
    li $v0, 10
    syscall

# Function to compute the next state of an LFSR
# Input parameter: $a0 = current state
# Output: $v0 = next state
lfsr_next_state:
    # Initialize upper mask with 0x8000 and lower mask with 0x0001
    lui $t0, 0x8000
    ori $t1, $zero, 0x0001
    # Initialize result with 0
    li $v0, 0
    # Loop through all 32 bits of the input state
    li $t2, 0
    li $t3, 0
lfsr_loop:
    # Shift the current state to the right
    srl $a0, $a0, 1
    # Get the least significant bit of the current state
    andi $t2, $a0, 1
    # If the least significant bit is 1, XOR with the tap mask
    beq $t2, 1, lfsr_xor
    j lfsr_continue
lfsr_xor:
    xor $a0, $a0, $t0
lfsr_continue:
    # Increment the loop counter
    addi $t3, $t3, 1
    # If the loop counter is less than 32, continue the loop
    blt $t3, 32, lfsr_loop
    # Set the result to the current state
    move $v0, $a0
    jr $ra

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

I ran the updated code that you provide with li $v0, 34 for printing an unsigned integer. I got an error saying:

Unknown system call: 34

This the the updated code that you provided:

        .data
        .globl main
        .text
main:
        # compute the next state of the LFSR for each input state
        li $a0, 0x00000001
        jal lfsr_next_state
        move $t0, $v0
        li $a0, 0xdeadbeef
        jal lfsr_next_state
        move $t1, $v0
        li $a0, 0x200214c8
        jal lfsr_next_state
        move $t2, $v0
        li $a0, 0x00000000
        jal lfsr_next_state
        move $t3, $v0

        # print the output states
        li $v0, 34  # set system call for printing unsigned integer
        move $a0, $t0
        syscall
        move $a0, $t1
        syscall
        move $a0, $t2
        syscall
        move $a0, $t3
        syscall

        # exit the program
        li $v0, 10
        syscall

# Function to compute the next state of an LFSR
# Input parameter: $a0 = current state
# Output: $v0 = next state
lfsr_next_state:
        # Initialize upper mask with 0x8000 and lower mask with 0x0001
        lui $t0, 0x8000
        ori $t1, $zero, 0x0001
        # Initialize result with 0
        li $v0, 0
        # Loop through all 32 bits of the input state
        li $t2, 0
        li $t3, 0
lfsr_loop:
        # Shift the current state to the right
        srl $a0, $a0, 1
        # Get the least significant bit of the current state
        andi $t2, $a0, 1
        # If the least significant bit is 1, XOR with the tap mask
        beq $t2, 1, lfsr_xor
        j lfsr_continue
lfsr_xor:
        xor $a0, $a0, $t0
lfsr_continue:
        # Increment the loop counter
        addi $t3, $t3, 1
        # If the loop counter is less than 32, continue the loop
        blt $t3, 32, lfsr_loop
        # Set the result to the current state
        move $v0, $a0
        jr $ra

 

I am running my code using the QtSpim. 

How do I fix this?

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

I ran the updated code that you provided.

This is my output:

-2147483648100

 

This is the updated code that you provided:

        .data
        .globl main
        .text
main:
        # compute the next state of the LFSR for each input state
        li $a0, 0x00000001
        jal lfsr_next_state
        move $t0, $v0
        li $a0, 0xdeadbeef
        jal lfsr_next_state
        move $t1, $v0
        li $a0, 0x200214c8
        jal lfsr_next_state
        move $t2, $v0
        li $a0, 0x00000000
        jal lfsr_next_state
        move $t3, $v0

        # print the output states
        li $v0, 1
        move $a0, $t0
        syscall
        li $v0, 1
        move $a0, $t1
        syscall
        li $v0, 1
        move $a0, $t2
        syscall
        li $v0, 1
        move $a0, $t3
        syscall

        # exit the program
        li $v0, 10
        syscall

# Function to compute the next state of an LFSR
# Input parameter: $a0 = current state
# Output: $v0 = next state
lfsr_next_state:
        # Initialize upper mask with 0x8000 and lower mask with 0x0001
        lui $t0, 0x8000
        ori $t1, $zero, 0x0001
        # Initialize result with 0
        li $v0, 0
        # Loop through all 32 bits of the input state
        li $t2, 0
        li $t3, 0
lfsr_loop:
        # Shift the current state to the right
        srl $a0, $a0, 1
        # Get the least significant bit of the current state
        andi $t2, $a0, 1
        # If the least significant bit is 1, XOR with the tap mask
        beq $t2, 1, lfsr_xor
        j lfsr_continue
lfsr_xor:
        xor $a0, $a0, $t0
lfsr_continue:
        # Increment the loop counter
        addi $t3, $t3, 1
        # If the loop counter is less than 32, continue the loop
        blt $t3, 32, lfsr_loop
        # Set the result to the current state
        move $v0, $a0
        jr $ra

 

How do I fix this?

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

I am still getting the same wrong output using the updated code that you provided. I moved the andi instruction after the srl instruction.

This is the code that you provided with the fix:

        .data
        .globl main
        .text
main:
        # compute the next state of the LFSR for each input state
        li $a0, 0x00000001
        jal lfsr_next_state
        move $t0, $v0
        li $a0, 0xdeadbeef
        jal lfsr_next_state
        move $t1, $v0
        li $a0, 0x200214c8
        jal lfsr_next_state
        move $t2, $v0
        li $a0, 0x00000000
        jal lfsr_next_state
        move $t3, $v0

        # print the output states
        li $v0, 1
        move $a0, $t0
        syscall
        li $v0, 1
        move $a0, $t1
        syscall
        li $v0, 1
        move $a0, $t2
        syscall
        li $v0, 1
        move $a0, $t3
        syscall

        # exit the program
        li $v0, 10
        syscall

# Function to compute the next state of an LFSR
# Input parameter: $a0 = current state
# Output: $v0 = next state
lfsr_next_state:
        # Initialize upper mask with 0x7fff and lower mask with 0x8000
        lui $t0, 0x7fff
        ori $t0, $t0, 0x8000
        # Initialize result with 0
        li $v0, 0
        # Loop through all 32 bits of the input state
        li $t1, 0
        li $t2, 0
        
lfsr_loop:
        # Shift the current state to the right
        srl $a0, $a0, 1
        # Get the least significant bit of the current state
        andi $t1, $a0, 1
        # If the least significant bit is 1, XOR with the tap mask
        beq $t1, 1, lfsr_xor
        j lfsr_continue
        
lfsr_xor:
        xor $a0, $a0, $t0
        
lfsr_continue:
        # Increment the loop counter
        addi $t2, $t2, 1
        # If the loop counter is less than 32, continue the loop
        blt $t2, 32, lfsr_loop
        # Set the result to the current state
        move $v0, $a0
        jr $ra

 

But the output is still the same wrong output. How do I fix this?

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

I am still getting the wrong output with the updated code with the fix.

This is the updated coded that you provided:

        .data
        .globl main
        .text
main:
        # compute the next state of the LFSR for each input state
        li $a0, 0x00000001
        jal lfsr_next_state
        move $t0, $v0
        li $a0, 0xdeadbeef
        jal lfsr_next_state
        move $t1, $v0
        li $a0, 0x200214c8
        jal lfsr_next_state
        move $t2, $v0
        li $a0, 0x00000000
        jal lfsr_next_state
        move $t3, $v0

        # print the output states
        li $v0, 1
        move $a0, $t0
        syscall
        li $v0, 1
        move $a0, $t1
        syscall
        li $v0, 1
        move $a0, $t2
        syscall
        li $v0, 1
        move $a0, $t3
        syscall

        # exit the program
        li $v0, 10
        syscall

# Function to compute the next state of an LFSR
# Input parameter: $a0 = current state
# Output: $v0 = next state
lfsr_next_state:
        # Initialize upper mask with 0x7fff and lower mask with 0x8000
        lui $t0, 0x7fff
        ori $t0, $t0, 0x8000
        # Initialize result with 0
        li $v0, 0
        # Loop through all 32 bits of the input state
        li $t1, 0
        li $t2, 0
        
lfsr_loop:
        # Get the least significant bit of the current state
        andi $t1, $a0, 1
        # Shift the current state to the right
        srl $a0, $a0, 1
        # If the least significant bit is 1, XOR with the tap mask
        beq $t1, 1, lfsr_xor
        j lfsr_continue
        
lfsr_xor:
        xor $a0, $a0, $t0
        
lfsr_continue:
        # Increment the loop counter
        addi $t2, $t2, 1
        # If the loop counter is less than 32, continue the loop
        blt $t2, 32, lfsr_loop
        # Set the result to the current state
        move $v0, $a0
        jr $ra

 

When I run this code, I am still getting the wrong output.

How do I fix this?

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

This is the updated code that I have:

        .data
        .globl main
        .text
main:
        # compute the next state of the LFSR for each input state
        li $a0, 0x00000001
        jal lfsr_next_state
        move $t0, $v0
        li $a0, 0xdeadbeef
        jal lfsr_next_state
        move $t1, $v0
        li $a0, 0x200214c8
        jal lfsr_next_state
        move $t2, $v0
        li $a0, 0x00000000
        jal lfsr_next_state
        move $t3, $v0

        # print the output states
        move $a0, $t0
        li $v0, 1
        syscall
        move $a0, $t1
        li $v0, 1
        syscall
        move $a0, $t2
        li $v0, 1
        syscall
        move $a0, $t3
        li $v0, 1
        syscall

        # exit the program
        li $v0, 10
        syscall

# Function to compute the next state of an LFSR
# Input parameter: $a0 = current state
# Output: $v0 = next state
lfsr_next_state:
        # Initialize upper mask with 0x7fff and lower mask with 0x8000
        lui $t0, 0x7fff
        ori $t0, $t0, 0x8000
        # Initialize result with 0
        li $v0, 0
        # Loop through all 32 bits of the input state
        li $t1, 0
        li $t2, 0
        
lfsr_loop:
        # Get the least significant bit of the current state
        andi $t1, $a0, 1
        # Shift the current state to the right
        srl $a0, $a0, 1
        # If the least significant bit is 1, XOR with the tap mask
        beq $t1, 1, lfsr_xor
        j lfsr_continue
        
lfsr_xor:
        xor $a0, $a0, $t0
        
lfsr_continue:
        # Increment the loop counter
        addi $t2, $t2, 1
        # If the loop counter is less than 32, continue the loop
        blt $t2, 32, lfsr_loop
        # Set the result to the current state
        move $v0, $a0
        jr $ra

 

When I run this code, the output is this:

21474508800320

 

How do I fix this?

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

This is follow-up question to the answer from the previous follow-up question. 

When I run the updated code, I'm only getting this output:

21474508800320

Is this correct?

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

This is follow-up question to the answer from the previous follow-up question. 

I'm getting an error on this line: 

andi $t0, $a0, 0x7fff8000 # mask off the lower 15 bits

The error says:

spim: (parser) immediate value (2147450880) out of range (0 .. 65535)

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

The LFSR needs to be written as function and the main function should call the LFSR function using the "jal" assemly instruction and "jr $ra" to go back to main function. Could you update the codes?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Fundamentals of Computer System
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY