-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompileToAsm.cpp
53 lines (37 loc) · 1.25 KB
/
CompileToAsm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Compiler.h"
#pragma warning(disable: 4996)
void Compiler::CompileToAsm()
{
char * asFile = Utils::getAsFileName(rawName);
Wrinst->OpenFile(asFile);
Wrinst->Writeln("format PE console");
Wrinst->Writeln("entry main");
Wrinst->Writeln("");
Wrinst->Writeln("include 'win32a.inc'");
Wrinst->Writeln("");
Wrinst->Writeln("section '.text' code readable executable");
for (Declaration * declare : *declares) {
Log("Assemblying declaration %s", declare->name);
declare->GenerateAsm(0);
}
Wrinst->Writeln("\tmov esp, ebp");
Wrinst->Writeln("\tpop ebp");
Wrinst->Writeln("\tcall [ExitProcess]");
Wrinst->Writeln("");
Wrinst->Writeln("section '.idata' import data readable");
Wrinst->Writeln("\tlibrary kernel32, 'kernel32.dll', \\");
Wrinst->Writeln("\tmsvcrt, 'msvcrt.dll'");
Wrinst->Writeln("");
Wrinst->Writeln("\timport kernel32, \\");
Wrinst->Writeln("\tExitProcess, 'ExitProcess'");
Wrinst->Writeln("");
Wrinst->Writeln("\timport msvcrt, \\");
Wrinst->Writeln("\tprintf, 'printf'");
Wrinst->Writeln("");
Wrinst->Writeln("section '.data' data readable writeable");
for (Declaration * declare : *declares) {
Log("Assemblying data in declaration %s", declare->name);
declare->GenerateDataAsm();
}
Wrinst->CloseFile();
}