Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ please add comments Write a C++ program called hw3.cpp that prompts the user for a file name, then does a limited number of syntax

c++ please add comments
image text in transcribed
Write a C++ program called hw3.cpp that prompts the user for a file name, then does a limited number of syntax checks on the file as an assembly language program. Here is a sample file containing a couple instructions: inc ax ret The output should be: This program displays information about a set of Intel-like assembly instructions Enter name of file with instructions (no spaces): 2lines_ok.txt 1. The increment opcode operand 1 : ax 2. The return opcode The requirements for the assignment. 1. Each line is a single assembly language statement. The first word on the line is the opcode, optionally followed by a list of operands, separated by commas. 2. There are only 3 supported opcodes: inc, je, ret. These represent operations to increment, jump if equal, and return. a. The increment and jump if equal opcodes each require exactly one operand, like the "ax" in the above example. The return opcode does not accept operands b. For the operand, you are only reading in the next "word" in the file. You are not checking to see if it is a valid operand 3. As shown above, for valid opcodes with the correct number of operands, just display the line number, what the opcode represents and, if appropriate, the operand. 4. Send error messages to cerr. The errors to check for are: a. If the opcode is valid - if not, display the error message as shown in the test cases, and then skip the rest of the line b. If the number of operands is correct. Note that since the opcodes have 0 or 1 operands, the only time you must worry about more than one operand is in the error case of 2 operands. You might find putting the operands in a stringstream make this case easier to handle, but you are not absolutely required to use stringstreams. 5. Style-wise, besides an overall comment for the file, create named constants for the three opcodes. Note that you do not have to create named constants for 0 and 1

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

Rules In Database Systems Third International Workshop Rids 97 Sk Vde Sweden June 26 28 1997 Proceedings Lncs 1312

Authors: Andreas Geppert ,Mikael Berndtsson

1997th Edition

3540635165, 978-3540635161

More Books

Students also viewed these Databases questions

Question

Describe the job youd like to be doing five years from now.

Answered: 1 week ago

Question

So what disadvantages have you witnessed? (specific)

Answered: 1 week ago