Answered step by step
Verified Expert Solution
Link Copied!

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 9: Runtime exception at 0x00400000: address out of range 0x00000000
The output should be:
Enter the first string (max 1024 character): AGGTAB
Enter the second string (max 1024 character): GXTXAYB
The length of LCS is 4
.data
prompt1: .asciiz "Enter the first string (max 1024 characters): "
prompt2: .asciiz "Enter the second string (max 1024 characters): "
result: .asciiz "The length of LCS is: "
.text .globl find_lcs
find_lcs: # Prologue addi $sp, $sp,-12 sw $ra,0($sp) sw $a0,4($sp) sw $a1,8($sp)
# Load arguments
lw $a0,0($a0) # Load address of the first string
lw $a1,0($a1) # Load address of the second string
# Check for null pointers
beqz $a0, end_lcs # If first string is null, return 0
beqz $a1, end_lcs # If second string is null, return 0
# Base case: if either string is empty, return 0
lb $t0,0($a0) # Load byte from the first string
beq $t0, $zero, end_lcs # If byte is null, return 0
lb $t0,0($a1) # Load byte from the second string
beq $t0, $zero, end_lcs # If byte is null, return 0
# Compare the first characters of both strings
lb $t0,0($a0)
lb $t1,0($a1)
beq $t0, $t1, equal_chars
# If characters are not equal, find LCS by considering both cases
# Case 1: Exclude first character of s1
addi $a0, $a0,1
jal find_lcs
move $s0, $v0 # Store result in $s0
# Case 2: Exclude first character of s2
lw $a0,4($sp) # Reload s1
addi $a1, $a1,1
jal find_lcs
move $s1, $v0 # Store result in $s1
# Choose the maximum LCS
bge $s0, $s1, end_lcs
move $v0, $s1
j end_lcs
equal_chars: # Characters are equal, move to the next characters addi $a0, $a0,1 addi $a1, $a1,1 jal find_lcs addi $v0, $v0,1 # Increment LCS by 1 j end_lcs
end_lcs: # Epilogue lw $ra,0($sp) lw $a0,4($sp) lw $a1,8($sp) addi $sp, $sp,12 jr $ra
# Read the first string
li $v0,8
la $a0,0x10010000 # Buffer for the first string
li $a1,1024
syscall
# Prompt user for the second string
li $v0,4
la $a0, prompt2
syscall
# Read the second string
li $v0,8
la $a0,0x10020000 # Buffer for the second string
li $a1,1024
syscall
# Call find_lcs
la $a0,0x10010000 # Address of the first string
la $a1,0x10020000 # Address of the second string
jal find_lcs
# Print the result
li $v0,4
la $a0, result
syscall
# Print the length of the LCS
move $a0, $v0
li $v0,1
syscall
# Exit
li $v0,10
syscall

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

More Books

Students also viewed these Databases questions