/* find the first character in string sl that is also in s2 */ char firstmatch (char *s1, char *s2) { char *temp; temp = sl; do { if (strchr( s2, *temp ) != 0) /* if this character is there */ /* /* else look again return where we found it */ */ return temp; temp++; } while (*temp != 0); return 0; /* found none of these chars */ char * strchr (register const char *s, int c) { do { if (*s == c) { return (char*)s; } } while (*s++Li return (0):

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The goal of this lab is to get familiar with how the program described in a high-level language (particularly C) is translated into MIPS assembly language. We will eventually build our own simulator in the next lab assignment. For this lab assignment, we don’t have a simulator to run MIPS assembly, so we will use an existing one, called MPLAB. A basic MPLAB tutorial will be provided separately.

Specifically, translate the following C procedure into MIPS Assembly. You are required to follow the conventional use for registers such as temporary vs. saved registers, maintaining procedure call stacks, proper parameter passing and returns, etc. Note that this procedure calls another (strchr) which is assumed to also comply with those conventions.

/* find the first character in string s1 that is

These are additional instructions to complete this lab assignment.

  • The program should consist of two segments: .data and .text segments.
  • Define two strings, str1 and str2, in the data segment.
  • Use lb (load byte) as you manipulate strings, not integers.
  • The code segment, labeled as “.text”, should begin with “main:” because the simulator begins the execution from there.
  • In the main code, you should start with the load addresses of the defined str1 and str2.
  • You need to write two procedures, firstmatch and strchr, in the code segment, each is labeled as the procedure name.
  • After loading string addresses, you pass both strings to firstmatch as in the above C code.
  • Within the firstmatch procedure, you need to call the strchr
  • When each procedure gets called, you need to follow the procedure calling conventions.

Write your firstmatch procedure, so the do-while loop contains six or fewer

/* find the first character in string sl that is also in s2 * /
char firstmatch (char *s1, char *s2)
{
char *temp;
temp = s1;
do {
if (strchr( s2, *temp ) != 0) /* if this character is there */
return temp;
temp++;
/*
/* else look again
return where we found it */
*/
} while (*temp != 0);
/* found none of these chars
*/
return 0;
}
|
char
{
do {
if (*s == c) {
return (char*)s;
}
} while (*s++):
strchr (register const char *s, int c)
return (0):
}
Transcribed Image Text:/* find the first character in string sl that is also in s2 * / char firstmatch (char *s1, char *s2) { char *temp; temp = s1; do { if (strchr( s2, *temp ) != 0) /* if this character is there */ return temp; temp++; /* /* else look again return where we found it */ */ } while (*temp != 0); /* found none of these chars */ return 0; } | char { do { if (*s == c) { return (char*)s; } } while (*s++): strchr (register const char *s, int c) return (0): }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education