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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!