Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Error in line 9 : Runtime exception at 0 x 0 0 4 0 0 0 0 0 : address out of range 0 x
Error in line : Runtime exception at x: address out of range x
The output should be:
Enter the first string max character: AGGTAB
Enter the second string max character: GXTXAYB
The length of LCS is
data
prompt: asciiz "Enter the first string max characters:
prompt: asciiz "Enter the second string max characters:
result: asciiz "The length of LCS is:
text globl findlcs
findlcs: # Prologue addi $sp $sp sw $ra$sp sw $a$sp sw $a$sp
# Load arguments
lw $a$a # Load address of the first string
lw $a$a # Load address of the second string
# Check for null pointers
beqz $a endlcs # If first string is null, return
beqz $a endlcs # If second string is null, return
# Base case: if either string is empty, return
lb $t$a # Load byte from the first string
beq $t $zero, endlcs # If byte is null, return
lb $t$a # Load byte from the second string
beq $t $zero, endlcs # If byte is null, return
# Compare the first characters of both strings
lb $t$a
lb $t$a
beq $t $t equalchars
# If characters are not equal, find LCS by considering both cases
# Case : Exclude first character of s
addi $a $a
jal findlcs
move $s $v # Store result in $s
# Case : Exclude first character of s
lw $a$sp # Reload s
addi $a $a
jal findlcs
move $s $v # Store result in $s
# Choose the maximum LCS
bge $s $s endlcs
move $v $s
j endlcs
equalchars: # Characters are equal, move to the next characters addi $a $a addi $a $a jal findlcs addi $v $v # Increment LCS by j endlcs
endlcs: # Epilogue lw $ra$sp lw $a$sp lw $a$sp addi $sp $sp jr $ra
# Read the first string
li $v
la $ax # Buffer for the first string
li $a
syscall
# Prompt user for the second string
li $v
la $a prompt
syscall
# Read the second string
li $v
la $ax # Buffer for the second string
li $a
syscall
# Call findlcs
la $ax # Address of the first string
la $ax # Address of the second string
jal findlcs
# Print the result
li $v
la $a result
syscall
# Print the length of the LCS
move $a $v
li $v
syscall
# Exit
li $v
syscall
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