So I've started writing my assembler now was just doing some little tests to determine the best way to read / write the words (unsigned short's typedef'd).
So far I have this:
Code:
int main(int argc, char* argv[])
{
FILE* f = fopen("PROGRAM.lvmp", "w");
word instruction[3] = {0};
cout << "instruction: ";
cin >> instruction[0];
cin >> instruction[1];
cin >> instruction[2];
fputc(instruction[0], f);
fputc(instruction[1], f);
fputc(instruction[2], f);
fclose(f);
f = fopen("PROGRAM.lvmp", "r");
instruction[0] = fgetc(f);
instruction[1] = fgetc(f);
instruction[2] = fgetc(f);
fclose(f);
cout << "opcode: " << instruction[0] << "\n";
cout << "op1: " << instruction[1] << "\n";
cout << "op2: " << instruction[2] << endl;
return 0;
}
It works fine unless I enter something like
(movl 10, r0)
In which case when fgetc reads it I get this output:
Code:
opcode: 3
op1: 10
op2: 251
If I give it 65535 (OP_END) op2 is read as 255. I can only guess that this is happening due to something to do with ASCII. How could I get around this? fgetc / fputc is probably not the best choice anyway.
Thoughts?