mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-23 06:18:54 +00:00
This commit is contained in:
parent
08ee17a829
commit
c09c0f2459
9 changed files with 113 additions and 6 deletions
|
|
@ -11,8 +11,26 @@ namespace HelloWorldAssembler {
|
|||
using (Assembler a = new Assembler(xSW)) {
|
||||
a.OutputType = Assembler.OutputTypeEnum.Console;
|
||||
a.Includes.Add("win32w.inc");
|
||||
a.DataMembers.Add(new DataMember("_class", "TCHAR", "'Win32 program template'"));
|
||||
new Invoke("GetModuleHandle", new object[] {0});
|
||||
a.DataMembers.Add(new DataMember("_class", "TCHAR", "'FASMWIN32'"));
|
||||
a.DataMembers.Add(new DataMember("_title", "TCHAR", "'Win32 program template'"));
|
||||
a.DataMembers.Add(new DataMember("_error", "TCHAR", "'Startup failed.'"));
|
||||
a.DataMembers.Add(new DataMember("wc", "WNDCLASS", "0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class"));
|
||||
new Invoke("GetModuleHandle", 0);
|
||||
new Move("[wc.hInstance]", "eax");
|
||||
new Invoke("LoadIcon", 0, "IDI_APPLICATION");
|
||||
new Move("[wc.hIcon]", "eax");
|
||||
new Invoke("LoadCursor", 0, "IDC_ARROW");
|
||||
new Move("[wc.hCursor]", "eax");
|
||||
new Invoke("RegisterClass", "wc");
|
||||
new Test("eax", "eax");
|
||||
new JumpIfZero("error");
|
||||
new Invoke("CreateWindowEx", 0, "_class", "_title", "WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU", 128, 128, 256, 192, "NULL", "NULL", "[wc.hInstance]", "NULL");
|
||||
new Test("eax", "eax");
|
||||
new JumpIfZero("error");
|
||||
new Label("msg_loop");
|
||||
new Invoke("GetMessage", "msg", "NULL", 0, 0);
|
||||
new Compare("eax", "1");
|
||||
|
||||
a.Flush();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,12 @@ namespace Indy.IL2CPU.Assembler {
|
|||
mOutputWriter.WriteLine();
|
||||
mOutputWriter.WriteLine(" " + EntryPointLabelName + ":");
|
||||
foreach (Instruction x in mInstructions) {
|
||||
mOutputWriter.WriteLine("\t" + x);
|
||||
string prefix = "\t";
|
||||
if (x is Label) {
|
||||
mOutputWriter.WriteLine();
|
||||
prefix = " ";
|
||||
}
|
||||
mOutputWriter.WriteLine(prefix + x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
source/Indy.IL2CPU.Assembler/Compare.cs
Normal file
18
source/Indy.IL2CPU.Assembler/Compare.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Indy.IL2CPU.Assembler {
|
||||
public class Compare: Instruction {
|
||||
public readonly string Address1;
|
||||
public readonly string Address2;
|
||||
public Compare(string aAddress1, string aAddress2) {
|
||||
Address1 = aAddress1;
|
||||
Address2 = aAddress2;
|
||||
}
|
||||
public override string ToString() {
|
||||
return "cmp " + Address1 + "," + Address2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,14 +50,18 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assembler.cs" />
|
||||
<Compile Include="Compare.cs" />
|
||||
<Compile Include="DataMember.cs" />
|
||||
<Compile Include="Instruction.cs" />
|
||||
<Compile Include="InstructionCPU.cs" />
|
||||
<Compile Include="Invoke.cs" />
|
||||
<Compile Include="JumpIfZero.cs" />
|
||||
<Compile Include="Label.cs" />
|
||||
<Compile Include="Literal.cs" />
|
||||
<Compile Include="Move.cs" />
|
||||
<Compile Include="OpCodeAttribute.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Test.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Indy.IL2CPU.Assembler {
|
|||
: this(aProcedureName, new object[0]) {
|
||||
}
|
||||
|
||||
public Invoke(string aProcedureName, object[] aParams) {
|
||||
public Invoke(string aProcedureName, params object[] aParams) {
|
||||
ProcedureName = aProcedureName;
|
||||
Params = aParams;
|
||||
}
|
||||
|
|
|
|||
16
source/Indy.IL2CPU.Assembler/JumpIfZero.cs
Normal file
16
source/Indy.IL2CPU.Assembler/JumpIfZero.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Indy.IL2CPU.Assembler {
|
||||
public class JumpIfZero: Instruction {
|
||||
public readonly string Address;
|
||||
public JumpIfZero(string aAddress) {
|
||||
Address = aAddress;
|
||||
}
|
||||
public override string ToString() {
|
||||
return "jz " + Address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,13 @@ using System.Linq;
|
|||
using System.Text;
|
||||
|
||||
namespace Indy.IL2CPU.Assembler {
|
||||
public class Label : Instruction {
|
||||
}
|
||||
public class Label: Instruction {
|
||||
public readonly string Name;
|
||||
public Label(string aName) {
|
||||
Name = aName;
|
||||
}
|
||||
public override string ToString() {
|
||||
return Name + ":";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
source/Indy.IL2CPU.Assembler/Move.cs
Normal file
19
source/Indy.IL2CPU.Assembler/Move.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Indy.IL2CPU.Assembler {
|
||||
public class Move: Instruction {
|
||||
public readonly string Destination;
|
||||
public readonly string Source;
|
||||
public Move(string aDestination, string aSource) {
|
||||
Destination = aDestination;
|
||||
Source = aSource;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return "mov " + Destination + "," + Source;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
source/Indy.IL2CPU.Assembler/Test.cs
Normal file
20
source/Indy.IL2CPU.Assembler/Test.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Indy.IL2CPU.Assembler {
|
||||
public class Test: Instruction {
|
||||
public readonly string Arg1;
|
||||
public readonly string Arg2;
|
||||
|
||||
public Test(string aArg1, string aArg2) {
|
||||
Arg1 = aArg1;
|
||||
Arg2 = aArg2;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return "test " + Arg1 + "," + Arg2;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue