8 Replies - 2110 Views - Last Post: 25 October 2009 - 05:08 PM Rate Topic: -----

#1 Nizbel99  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 117
  • Joined: 19-May 09

C++ Assignment Question

Posted 03 October 2009 - 02:02 PM

Hello everyone. For my assignment, we are required to make an assembler. I know this can be quite complicated,
but my question is pretty simple.

"Each problem in Part II requires you to submit a program in Java, Scheme, C or C++ that reads from standard input and writes to standard output as well as standard error. The input and output specifications are identical regardless of which language you choose. The only difference is that you must submit the appropriate .java, .ss, .c or .cc file depending on your choice of language. Do all of your work within this one file (Asm.java or asm.ss or asm.c or asm.cc). In any case where the input is not a valid assembly language program, your assembler should print an appropriate error message to standard error (System.err.println(String) in Java) indicating the location and nature of the error it has encountered. Each error message must contain the string ERROR, in all capitals. Your assembler should not crash in other ways, even if the input is not a valid assembly language program. Your assembler should not silently ignore errors in the input program."

Essentially, I'm writting this in C++, and I was wondering what the "Standard Error" was? I've heard of standard input and output, but i've never heard of a standard error before. I would I print too it? I've looked on google briefly and can't really seem to find anything. Can anyone explain to me what this is and how I could print too it?
If someone could also provide a link with more information, that would also be useful.

I want to get started early, since I know I have a LONG LONG journy ahead xD :) - Wish me luck, and thanks for the help. And for those of you who are curious, this is going to be a MIPS assembler when finished :)

Thanks,

Zach

Is This A Good Question/Topic? 0
  • +

Replies To: C++ Assignment Question

#2 Hiram  Icon User is offline

  • D.I.C Head

Reputation: 69
  • View blog
  • Posts: 203
  • Joined: 02-June 09

Re: C++ Assignment Question

Posted 03 October 2009 - 02:11 PM

http://www.cplusplus.../iostream/cerr/

Standard error is basically like cout, but specifically for errors. But if you actually use cout in your program, you may not want the user to see the larger-scale errors in the middle of the program too, so you write them to cerr. By default, I'm pretty sure the standard error's output is to stdout, but it can be redirected obviously.

I'm sure a common practice would be to redirect cerr's output to a text file, thus creating logs.
Was This Post Helpful? 0
  • +
  • -

#3 Nizbel99  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 117
  • Joined: 19-May 09

Re: C++ Assignment Question

Posted 03 October 2009 - 02:15 PM

Yes, writting the errors to a logfile would seem logical, but I don't think that for this assignment they want us too.
All our programs our graded automatically for the required output or return values (depending on what the assigment is). Anyways, so I would just use cerr the same way I would use cout, except only for errors?

Thanks for your help :)

Zach

This post has been edited by Nizbel99: 03 October 2009 - 02:15 PM

Was This Post Helpful? 0
  • +
  • -

#4 Hiram  Icon User is offline

  • D.I.C Head

Reputation: 69
  • View blog
  • Posts: 203
  • Joined: 02-June 09

Re: C++ Assignment Question

Posted 03 October 2009 - 02:28 PM

Yep, that's it! Same as cout, except for errors. Glad I could help, and good luck! :P
Was This Post Helpful? 1
  • +
  • -

#5 Nizbel99  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 117
  • Joined: 19-May 09

Re: C++ Assignment Question

Posted 03 October 2009 - 02:31 PM

Sorry about posting again right away, but I kept reading the instructions they gave us, and there's something else that I'm not too sure as to how I would too. Since our output has to be binary, they don't want us to print the ascii characters "0" or "1", but instead the actual binary equivilant in bits. Does anyone have any suggestions as to how
I could approach this issue? (Other information on bit manipulation that isn't too complicated might also be useful)

I'm sorry about all of the questions, and I'm usually pretty good at programming in C++, but alot of these things are new concepts to me that we're learning in our CS classes. Thanks for the help everyone,

Zach
Was This Post Helpful? 0
  • +
  • -

#6 Hiram  Icon User is offline

  • D.I.C Head

Reputation: 69
  • View blog
  • Posts: 203
  • Joined: 02-June 09

Re: C++ Assignment Question

Posted 03 October 2009 - 02:48 PM

If you google something like "c++ print binary" you find some pretty good stuff. So, ALL of your output has to be binary? That's hardly readable :P well not easily.
Was This Post Helpful? 0
  • +
  • -

#7 Nizbel99  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 117
  • Joined: 19-May 09

Re: C++ Assignment Question

Posted 03 October 2009 - 02:52 PM

All I can seem to find is printing a binary equivilant, but they use the ASCII characters "0" and "1" ... we need
to actually print the bits. This is where the problem comes in...

Yeah it isn't really readable, but that's what an assembler does :P

Thanks again, all the help is appreciated,

Zach
Was This Post Helpful? 0
  • +
  • -

#8 Hiram  Icon User is offline

  • D.I.C Head

Reputation: 69
  • View blog
  • Posts: 203
  • Joined: 02-June 09

Re: C++ Assignment Question

Posted 03 October 2009 - 03:23 PM

// to-binary-bitops.cpp  Print binary representation of ints
// Fred Swartz  - 2001-09-04

#include <iostream>
using namespace std;

int main() {
	int n;
	while (cin >> n) {
		cout << "decimal: " << n << endl;

		// print binary with leading zeros
		cout << "binary : ";
		for (int i=31; i>=0; i--) {
			int bit = ((n >> i) & 1);
			cout << bit;
		}
		cout << endl;
	}//end loop
	return 0;
}//end main



http://www.uow.edu.a...inbybitops.html

The example off of this page doesn't use any ASCII characters, however it doesn't accept characters. It wouldn't be hard to change it to accept them though.
Was This Post Helpful? 0
  • +
  • -

#9 Nizbel99  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 117
  • Joined: 19-May 09

Re: C++ Assignment Question

Posted 25 October 2009 - 05:08 PM

Well, It's finished :D - It took a while, but I made an MIPS assembler that works great, and seems to do the job really efficiently (thanks to hash tables).
I'm really proud, and it's by far the hardest thing I had to make :D

Now that I understand how things are assembled, I was wondering if it would be much harder to work your way backwards to make a dis-assembler? Would that be much harder to do? Or would it be something that can be done with a fair amount of work?

Thanks,

Zach
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1