Answered step by step
Verified Expert Solution
Link Copied!

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 MIPS32)(SOME ERRORS I GOT FROM OTHER SOLUTIONS: Runtime exception at 0x0040001c: address out of range 0x00000000, "max" is not a recognized operator the solution with errors is provided)
.data
s1_prompt: .asciiz "Enter the first string (max 1024 characters): "
s2_prompt: .asciiz "Enter the second string (max 1024 characters): "
lcs_result: .asciiz "The length of LCS is "
.text
.globl main
main:
# Prompt user for the first string
li $v0,4
la $a0, s1_prompt
syscall
# Read the first string from the user
li $v0,8
la $a0,0 # Buffer address
li $a1,1024 # Buffer size
syscall
# Prompt user for the second string
li $v0,4
la $a0, s2_prompt
syscall
# Read the second string from the user
li $v0,8
la $a0,0 # Buffer address
li $a1,1024 # Buffer size
syscall
# Call find_lcs function
la $a0,0 # Address of the first string
la $a1,0 # Address of the second string
jal find_lcs # Jump and link to find_lcs function
# Print the result
li $v0,4
la $a0, lcs_result
syscall
# Print the length of LCS
li $v0,1
move $a0, $v0 # The length of LCS is stored in $v0
syscall
# Exit program
li $v0,10
syscall
# Recursive function to find the length of LCS
# Input: $a0- address of the first string
# $a1- address of the second string
find_lcs:
lb $t0,0($a0) # Load the first character from the first string
lb $t1,0($a1) # Load the first character from the second string
beq $t0, $zero, exit_find_lcs # If end of string 1 is reached, return 0
beq $t1, $zero, exit_find_lcs # If end of string 2 is reached, return 0
beq $t0, $t1, matching_chars # If characters match, jump to matching_chars
j non_matching_chars
matching_chars:
addi $a0, $a0,1 # Move to the next character in string 1
addi $a1, $a1,1 # Move to the next character in string 2
jal find_lcs # Recursive call
addi $v0, $v0,1 # Increment result by 1(matching character)
j exit_find_lcs
non_matching_chars:
addi $a0, $a0,1 # Move to the next character in string 1
jal find_lcs # Recursive call
move $t2, $v0 # Store result in $t2
addi $a0, $a0,-1 # Backtrack to the previous character in string 1
addi $a1, $a1,1 # Move to the next character in string 2
jal find_lcs # Recursive call
move $t3, $v0 # Store result in $t3
max $v0, $t2, $t3 # Select the maximum of the two results
j exit_find_lcs
exit_find_lcs:
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 in-air signatures
Implementation:
Define Function: find_lcs
Inputs:
,s1, an address of the first null-terminated string in Register $a0.
, S2, an address of the second null-terminated string in Register $a1
Outputs:
,N, the size of the longest common sequence in Register $v0.
You are asked to write recursive function that find the LCS between two null-terminated strings. The function receives the address of two strings S1 and S2 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 (i.e. can be called from another file). Refer to the C code given below:
int find_lcs(string s1, string s2)
{
if
image text in transcribed

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

Logidata+ Deductive Databases With Complex Objects Lncs 701

Authors: Paolo Atzeni

1st Edition

354056974X, 978-3540569749

More Books

Students also viewed these Databases questions

Question

What is the purpose of calculating a pension plans funded ratio?

Answered: 1 week ago

Question

RP-2 How do our attitudes and our actions affect each other?

Answered: 1 week ago

Question

Distinguish between filtering and interpreting. (Objective 2)

Answered: 1 week ago