lease Modify this code according to this instructions   cmds.c   – Need to modify the Cmd struct to include:   “ms” and “h”   – Add code in mem_display

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.1: Function And Parameter Declarations
Problem 11E
icon
Related questions
Question

plese modify the code according to the instruction in c programming 

Please Modify this code according to this instructions

 

cmds.c

 

– Need to modify the Cmd struct to include:

 

“ms” and “h”

 

– Add code in mem_display(), help(), mem_set() functions

 

– Command routine calls with 2 arguments, e.g.

 

  • mem_display(Cmd *cp, char *arguments)

 

&cmds[0]

 

Address of the string “10000”

 

– If we enter a command “md 10000” to display the contents of 16 locations starting with 10000, the arguments passed are:

 

 

 

file:     cmds.c

 

/* the Makefile arranges that #include <..> searches in the right

   places for these headers-- 200920*/

 

#include <stdio.h>

#include "slex.h"

/*===================================================================*

*

*   Command table for tutor program -- an array of structures of type

*   cmd -- for each command provide the token, the function to call when

*   that token is found, and the help message.

*

*   slex.h contains the typdef for struct cmd, and declares the

*   cmds array as extern to all the other parts of the program.

*   Code in slex.c parses user input command line and calls the

*   requested semantic action, passing a pointer to the cmd struct

*   and any arguments the user may have entered.

*

*===================================================================*/

 

PROTOTYPE int stop(Cmd *cp, char *arguments);

PROTOTYPE int mem_display(Cmd *cp, char *arguments);

 

/* command table */

 

Cmd cmds[] = {{"md",  mem_display, "Memory display: MD <addr>"},

              {"s",   stop,        "Stop" },

              {NULLNULL,        NULL}};  /* null cmd to flag end of table */

 

char xyz = 6;  /* test global variable  */

char *pxyz = &xyz;  /* test pointer to xyz */

/*===================================================================*

*               command                 routines

*

*   Each command routine is called with 2 args, the remaining

*   part of the line to parse and a pointer to the struct cmd for this

*   command. Each returns 0 for continue or 1 for all-done.

*

*===================================================================*/

 

int stop(Cmd *cp, char *arguments)

{

  return 1;                     /* all done flag */

}

 

 

 

/*===================================================================*

*

*   mem_display: display contents of 16 bytes in hex

*

*/

 

int mem_display(Cmd *cp, char *arguments)

{

  printf("Reached mem_display, passed argument string: |%s|\n", arguments);

  printf("        help message: %s\n", cp->help);

  return 0;                     /* not done */

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Introduction to computer system
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning