Question
ADD to the below another scan format to parse that reads: Input lines: 1. addu $v0, $zero, $s10 ( with spaces between the source codes)
ADD to the below another scan format to parse that reads:
Input lines:
1. addu $v0, $zero, $s10 ( with spaces between the source codes)
2. J L1
/*
*
* For detailed info regarding fgets, refer manpage at linprog
* % man 3 fgets
*
*/
#include
#define MAXLINE 80
#define MAXREG 5
int main()
{
char line[MAXLINE]={0};
char oper[MAXLINE];
char rd[MAXREG],rs[MAXREG],rt[MAXREG];
while (fgets(line, MAXLINE, stdin)) {
/* check if a 3-address R format instruction */
if (sscanf(line, "%s $%[^,],$%[^,],$%s", oper, rd, rs, rt) == 4) {
printf("input line: %s ", line);
printf("parsed line: op:%10s rd:%5s rs:%5s rt:%5s ",
oper, rd, rs, rt);
}
/* you need to add other patterns for R,I,and J encoding */
else {
printf("input line: %s ", line);
printf("you need to add sscanf format ");
}
}
return 0;
}
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