diff --git a/Assembler.cpp b/Assembler.cpp index e1d2a69..a11186e 100644 --- a/Assembler.cpp +++ b/Assembler.cpp @@ -185,19 +185,9 @@ string functionForC(string s) Bits_16 = Bits_16 + J_Code(jump); //concatinate the 13 bits with 3 bits of jump return Bits_16; //return the 16 bits number which we can write into file later on } +//----------------------------------------------Handling file---------------------------------------------------- -//-----------------------------------------------main func()----------------------------------------------------- - -int main() -{ - string filename; - cout << "Enter the File name : "; //open the appropriate file - cin >> filename; - filename = filename.substr(0, filename.find('.')); //if you enter test.asm this instruction filter it to test - string hack; - hack = filename + ".hack"; //filtered test+.hack makes test.hack - //cout << hack << endl << filename; - //reading the asm file 👍 +void Files(string filename,string hack){ fstream assemblyFile, outputFile; //.asm and hack files assemblyFile.open(filename + ".asm", ios::in); outputFile.open(hack, ios::out); @@ -337,6 +327,18 @@ int main() outputFile.close(); //closing the files assemblyFile.close(); //closing the files - } +} +} +//-----------------------------------------------main func()----------------------------------------------------- + +int main() +{ + string filename; + cout << "Enter the File name : "; //open the appropriate file + cin >> filename; + filename = filename.substr(0, filename.find('.')); //if you enter test.asm this instruction filter it to test + string hack; + hack = filename + ".hack"; //then the filtered test is concatenated with .hack + Files(filename,hack); //calling the function it will handle everything return 0; } diff --git a/Assembler.exe b/Assembler.exe new file mode 100644 index 0000000..25fae4d Binary files /dev/null and b/Assembler.exe differ diff --git a/test.asm b/test.asm index f9007ed..49a65e9 100644 --- a/test.asm +++ b/test.asm @@ -73,12 +73,11 @@ D;JEQ @New D=M @Y -M=M+D +M=D+M @Temp3 M=M-1 @LOOP3 0;JMP (End) @End -0;JMP - +0;JMP \ No newline at end of file diff --git a/test.hack b/test.hack new file mode 100644 index 0000000..1c7813d --- /dev/null +++ b/test.hack @@ -0,0 +1,67 @@ +0000000000001000 +1110110000010000 +0000000000010000 +1110001100001000 +0000000000001001 +1110110000010000 +0000000000010001 +1110001100001000 +0000000000010000 +1111110000010000 +0000000000010010 +1110001100001000 +0000000000010001 +1111110000010000 +0000000000010011 +1110001100001000 +0000000000010011 +1111110000010000 +0000000000011010 +1110001100000010 +0000000000010010 +1111110111001000 +0000000000010011 +1111110010001000 +0000000000010000 +1110101010000111 +0000000000010000 +1111110000010000 +0000000000010100 +1110001100001000 +0000000000010010 +1111110000010000 +0000000000010101 +1110001100001000 +0000000000010100 +1111110000010000 +0000000000101100 +1110001100000010 +0000000000010101 +1111110111001000 +0000000000010100 +1111110010001000 +0000000000100010 +1110101010000111 +0000000000010001 +1111110000010000 +0000000000010110 +1110001100001000 +1111110010001000 +0000000000010101 +1111110000010000 +0000000000010111 +1110001100001000 +0000000000010110 +1111110000010000 +0000000001000001 +1110001100000010 +0000000000010111 +1111110000010000 +0000000000010101 +1111000010001000 +0000000000010110 +1111110010001000 +0000000000110101 +1110101010000111 +0000000001000001 +1110101010000111