I compiled this code in dev c++ and i got 0 warnings and 0 errors, so it was a clean compile and whenever i run the exe i get this error which says

assembler.exe has encountered a problem and needs to close. And gives me the error report thingy for microsoft. I was wondering if someone else can compile the code and run it on there machine to see if its just my machine or something and if they have advice on why the program is crashing everytime. Thanks in advance

#include <iostream>
#include <fstream>
using namespace std;


int main()
{
    
string op;
int val1;
int val2;
string val3;
string val4;
int ElementAmount;


ifstream sourcefile;
sourcefile.open("program.code");

while (sourcefile >> op >> val3 >> val4)
{
ElementAmount = ElementAmount + 3;
}

sourcefile.close();

char binary[ElementAmount];

ifstream sourcefile1;
sourcefile1.open("program.code");
     
while (sourcefile1 >> op >> val1 >> val2)
{

if (op == "storeByte")
{
// storeByte 0 20
}

if (op == "storeWord")
{
// storeWord 0 20
}

if (op == "storeDword")
{
// storeDword 0 20
}

if (op == "moveMR")
{
// moveMR Eax 23
}

if (op == "moveRM")
{
// moveRM 2 Eax
}

if (op == "moveRR")
{
// moveRR Eax Ebx
}

if (op == "add")
{
// add Eax Ebx
}

if (op == "sub")
{
// sub Eax Ebx
}

}

sourcefile1.close();

ofstream binaryfile;
binaryfile.open ("program.bin", ios::out | ios::binary); 
binaryfile.write (binary, 512);
binaryfile.close();

}

It's impossible to compile this code: char binary[ElementAmount]; declaraion where ElementAmount is not initialized variable is wrong.
Post another "0 warning 0 errors" snippet ;)...

You should initialize ElementAmount to zero. Note that if you compile with the -pedantic option, you'll get an error about variable-size array usage, i.e. you might want to change ...

char binary[ElementAmount];

to

char * binary = new char[ElementAmount];
#include <iostream>
#include <fstream>
using namespace std;

int main() {

	string op;
	int val1;
	int val2;
	string val3;
	string val4;
	int ElementAmount = 0;

	ifstream sourcefile;
	sourcefile.open("program.code");
	if (!sourcefile.is_open()) {
		cout << "can't open program.code" << endl;
		return 1;
	}
	while (sourcefile >> op >> val3 >> val4) {
		ElementAmount += 3;
	}

	sourcefile.close();

	char* binary = new char[ElementAmount];
	memset(binary, 0, sizeof(binary));
	ifstream sourcefile1;
	sourcefile1.open("program.code");
	if (!sourcefile1.is_open()) {
		cout << "can't open program.code" << endl;
		return 1;
	}

	while (sourcefile1 >> op >> val1 >> val2) {

		if (op == "storeByte") {
			// storeByte 0 20
		}

		if (op == "storeWord") {
			// storeWord 0 20
		}

		if (op == "storeDword") {
			// storeDword 0 20
		}

		if (op == "moveMR") {
			// moveMR Eax 23
		}

		if (op == "moveRM") {
			// moveRM 2 Eax
		}

		if (op == "moveRR") {
			// moveRR Eax Ebx
		}

		if (op == "add") {
			// add Eax Ebx
		}

		if (op == "sub") {
			// sub Eax Ebx
		}

	}

	sourcefile1.close();

	ofstream binaryfile;
	binaryfile.open("program.bin", ios::out | ios::binary);
	binaryfile.write(binary, sizeof(binary));
	binaryfile.close();
	delete[] binary;
}

ok thanks ill try that, but what does these two lines of code do?
does it generate a new char element in the binary array for the value of elementamount?
and i dont understand the memset thing

char* binary = new char[ElementAmount];
memset(binary, 0, sizeof(binary));

i dont understand the memset thing

char* binary = new char[ElementAmount];
memset(binary, 0, sizeof(binary));

That code is a beginner's error, and tends to yield bugs that are hard to track down. The memset() call should, presumably, be "memset(binary, 0, ElementAmount);" to set all bytes in the dynamically allocated array binary to zero.

my input from the parse comes in from a string but my I need to put that data after im done with it inside a char array and it says it cant convert them but how can i parse something with a char array word by word i dont want an entire line.

This article has been dead for over six months. Start a new discussion instead.