From 5f9010f0bccffdcd7bb40ecabd6bf95bc0be0300 Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Sun, 2 Sep 2007 11:16:24 +0000 Subject: [PATCH] refactoring: moved DummyOp to its own c# file --- source/HelloWorldAssembler/DummyOp.cs | 47 +++++++++++++++++++ .../HelloWorldAssembler.csproj | 1 + source/HelloWorldAssembler/Program.cs | 42 ----------------- 3 files changed, 48 insertions(+), 42 deletions(-) create mode 100644 source/HelloWorldAssembler/DummyOp.cs diff --git a/source/HelloWorldAssembler/DummyOp.cs b/source/HelloWorldAssembler/DummyOp.cs new file mode 100644 index 000000000..8d04aaff6 --- /dev/null +++ b/source/HelloWorldAssembler/DummyOp.cs @@ -0,0 +1,47 @@ +using System; +using System.Linq; + +namespace HelloWorldAssembler { + public class DummyOp: Indy.IL2CPU.IL.X86.Op { + public override void Assemble(Mono.Cecil.Cil.Instruction aInstruction) { + Invoke("GetModuleHandle", 0); + Move("[wc.hInstance]", "eax"); + Invoke("LoadIcon", 0, "IDI_APPLICATION"); + Move("[wc.hIcon]", "eax"); + Invoke("LoadCursor", 0, "IDC_ARROW"); + Move("[wc.hCursor]", "eax"); + Invoke("RegisterClass", "wc"); + Test("eax", "eax"); + JumpIfZero("error"); + Invoke("CreateWindowEx", 0, "_class", "_title", "WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU", 128, 128, 256, 192, "NULL", "NULL", "[wc.hInstance]", "NULL"); + Test("eax", "eax"); + JumpIfZero("error"); + Label("msg_loop"); + Invoke("GetMessage", "msg", "NULL", 0, 0); + Compare("eax", "1"); + JumpIfGreater("end_loop"); + JumpIfNotZero("msg_loop"); + Invoke("TranslateMessage", "msg"); + Invoke("DispatchMessage", "msg"); + JumpAlways("msg_loop"); + Label("error"); + Invoke("MessageBox", "NULL", "_error", "NULL", "MB_ICONERROR+MB_OK"); + Label("end_loop"); + Invoke("ExitProcess", "[msg.wParam]"); + Literal("proc WindowProc hwnd,wmsg,wparam,lparam"); + Push("ebx", "esi", "edi"); + Compare("[wmsg]", "WM_DESTROY"); + JumpIfEquals(".wmdestroy"); + Label(".defwndproc"); + Invoke("DefWindowProc", "[hwnd]", "[wmsg]", "[wparam]", "[lparam]"); + JumpAlways(".finish"); + Label(".wmdestroy"); + Invoke("PostQuitMessage", "0"); + Xor("eax", "eax"); + Label(".finish"); + Pop("edi", "esi", "ebx"); + Ret(); + Literal("endp"); + } + } +} \ No newline at end of file diff --git a/source/HelloWorldAssembler/HelloWorldAssembler.csproj b/source/HelloWorldAssembler/HelloWorldAssembler.csproj index c3db7520f..28c181d75 100644 --- a/source/HelloWorldAssembler/HelloWorldAssembler.csproj +++ b/source/HelloWorldAssembler/HelloWorldAssembler.csproj @@ -45,6 +45,7 @@ + diff --git a/source/HelloWorldAssembler/Program.cs b/source/HelloWorldAssembler/Program.cs index 266c8148f..cc01fba57 100644 --- a/source/HelloWorldAssembler/Program.cs +++ b/source/HelloWorldAssembler/Program.cs @@ -6,48 +6,6 @@ using X86 = Indy.IL2CPU.Assembler.X86; using Indy.IL2CPU.Assembler.X86; namespace HelloWorldAssembler { - public class DummyOp: Indy.IL2CPU.IL.X86.Op { - public override void Assemble(Mono.Cecil.Cil.Instruction aInstruction) { - Invoke("GetModuleHandle", 0); - Move("[wc.hInstance]", "eax"); - Invoke("LoadIcon", 0, "IDI_APPLICATION"); - Move("[wc.hIcon]", "eax"); - Invoke("LoadCursor", 0, "IDC_ARROW"); - Move("[wc.hCursor]", "eax"); - Invoke("RegisterClass", "wc"); - Test("eax", "eax"); - JumpIfZero("error"); - Invoke("CreateWindowEx", 0, "_class", "_title", "WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU", 128, 128, 256, 192, "NULL", "NULL", "[wc.hInstance]", "NULL"); - Test("eax", "eax"); - JumpIfZero("error"); - Label("msg_loop"); - Invoke("GetMessage", "msg", "NULL", 0, 0); - Compare("eax", "1"); - JumpIfGreater("end_loop"); - JumpIfNotZero("msg_loop"); - Invoke("TranslateMessage", "msg"); - Invoke("DispatchMessage", "msg"); - JumpAlways("msg_loop"); - Label("error"); - Invoke("MessageBox", "NULL", "_error", "NULL", "MB_ICONERROR+MB_OK"); - Label("end_loop"); - Invoke("ExitProcess", "[msg.wParam]"); - Literal("proc WindowProc hwnd,wmsg,wparam,lparam"); - Push("ebx", "esi", "edi"); - Compare("[wmsg]", "WM_DESTROY"); - JumpIfEquals(".wmdestroy"); - Label(".defwndproc"); - Invoke("DefWindowProc", "[hwnd]", "[wmsg]", "[wparam]", "[lparam]"); - JumpAlways(".finish"); - Label(".wmdestroy"); - Invoke("PostQuitMessage", "0"); - Xor("eax", "eax"); - Label(".finish"); - Pop("edi", "esi", "ebx"); - Ret(); - Literal("endp"); - } - } public class Program { public static void Main(string[] args) { using (StreamWriter xSW = new StreamWriter("out.asm")) {