Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Introduction: ( Assembly MIPS 3 2 ) ( SOME ERRORS I GOT FROM OTHER SOLUTIONS: Runtime exception at 0 x 0 0 4 0 0
Introduction: Assembly MIPSSOME ERRORS I GOT FROM OTHER SOLUTIONS: Runtime exception at xc: address out of range x "max" is not a recognized operator the solution with errors is provided
data
sprompt: asciiz "Enter the first string max characters:
sprompt: asciiz "Enter the second string max characters:
lcsresult: asciiz "The length of LCS is
text
globl main
main:
# Prompt user for the first string
li $v
la $a sprompt
syscall
# Read the first string from the user
li $v
la $a # Buffer address
li $a # Buffer size
syscall
# Prompt user for the second string
li $v
la $a sprompt
syscall
# Read the second string from the user
li $v
la $a # Buffer address
li $a # Buffer size
syscall
# Call findlcs function
la $a # Address of the first string
la $a # Address of the second string
jal findlcs # Jump and link to findlcs function
# Print the result
li $v
la $a lcsresult
syscall
# Print the length of LCS
li $v
move $a $v # The length of LCS is stored in $v
syscall
# Exit program
li $v
syscall
# Recursive function to find the length of LCS
# Input: $a address of the first string
# $a address of the second string
findlcs:
lb $t$a # Load the first character from the first string
lb $t$a # Load the first character from the second string
beq $t $zero, exitfindlcs # If end of string is reached, return
beq $t $zero, exitfindlcs # If end of string is reached, return
beq $t $t matchingchars # If characters match, jump to matchingchars
j nonmatchingchars
matchingchars:
addi $a $a # Move to the next character in string
addi $a $a # Move to the next character in string
jal findlcs # Recursive call
addi $v $v # Increment result by matching character
j exitfindlcs
nonmatchingchars:
addi $a $a # Move to the next character in string
jal findlcs # Recursive call
move $t $v # Store result in $t
addi $a $a # Backtrack to the previous character in string
addi $a $a # Move to the next character in string
jal findlcs # Recursive call
move $t $v # Store result in $t
max $v $t $t # Select the maximum of the two results
j exitfindlcs
exitfindlcs:
jr $ra
Logest Common Sequence LCS is the longest subsequence that is common in two given sequences, provided that the elements of the subsequence are not required to occupy consecutive positions within the original sequences. LCS is used in compressing genome resequencing data and to authenticate users within their mobile phone through inair signatures
Implementation:
Define Function: findlcs
Inputs:
an address of the first nullterminated string in Register $
S an address of the second nullterminated string in Register $a
Outputs:
the size of the longest common sequence in Register $
You are asked to write recursive function that find the LCS between two nullterminated strings. The function receives the address of two strings S and S as a parameter and return the length of the longest common sequence as an output. The label of the function should be declared as global ie can be called from another file Refer to the code given below:
int findlcsstring s string s
if
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started