Title Win32 Assembly
Status Completed
Start Date 7-2003
End Date 7-2003
Version 1.0

Win32 Assembly

It is sometimes useful to have utilities that allow for GUI based copy and pasting of code. For example, in decoding part of a network dump, it may be easier to copy and paste the code than to write another program to scan for the part of the dump that you want. Because of this, I chose to make a win32 template to build off of. As a test of features, I chose to incorporate another concurrent project: the expression evaluator (ultimate simplistic version).

The normal win32 development tools like Visual Studio are undesireable because they generate bloated code and use un-intuitive interfaces. I decided to write the code in assembly for this reason. The assembler used was the netwide assembler. I believe that this is one of the best assemblers. I used to love the a86 assembler because it worked with the simplest syntax. But nasm is open source, and is very concrete. By concrete I mean that it doesn't do anything that you don't explicitly tell it to. To the coder this means total control. The best aspect is that all memory references have square brackets and all memory addresses have no square brackets. This is much more intuitive than the other system, which sometimes replaces the variables by the dereferenced values.

Writing win32 in NASM tutorial
-to compile: nasm -fobj filename.asm
-then link in the library: alink -oPE filename [other assembled files] win32.lib

ASM Problems:

  1. I needed to IMPORT functions from DLLs
    Pitfall: Not putting brackets around calls to imported functions
  2. Need DispatchMessage in Message Pump or window never shows up
    -this is what calls the window procedure
  3. Need to IMPORT InitCommonControls from comctl32.dll for extra controls
    - Not needed for buttons, editbox, etc.

Linking:

  1. C programs compiled with djgpp require that the caller resets the stack pointer for any parameters that they pass on the stack (which is the calling convention used)
  2. There is some strange reason that using the stack through inline asm and calling functions causes access violations. The workaround is to inline all the functions used.
  3. Windows XP does not provide assembly emulation, so using the hardware stack won't work. Of course you can just implement a software stack data structure.