This commit is contained in:
mterwoord_cp 2007-08-30 17:33:25 +00:00
parent 08ee17a829
commit c09c0f2459
9 changed files with 113 additions and 6 deletions

View file

@ -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();
}
}

View file

@ -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);
}
}
}

View 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;
}
}
}

View file

@ -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.

View file

@ -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;
}

View 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;
}
}
}

View file

@ -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 + ":";
}
}
}

View 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;
}
}
}

View 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;
}
}
}