Our intention is to write portable code that may be used on both 32-bit and 64-bit Windows and Linux platforms. This may either sound impossible or very tedious work, but it is quite simple. First of all, we have to define a few constants and macros, which will ease our further work, so let's begin by creating the platform.inc and crypto.asm source files where the latter is the main source file and the one we will compile.
Flat Assembler is capable of producing files in a variety of formats, beginning with raw binary output and DOS executables, through Windows-specific formats and up to Linux binaries (both executable and object). It is assumed that you are familiar with at least some of the following formats:
- 32-bit Windows object file (MS COFF format)
- 64-bit Windows object file (MS64 COFF format)
- 32-bit Windows DLL
- 64-bit Windows DLL
- 32-bit Linux object file (ELF)
- 64-bit Linux object file (ELF64)
There is no need to be deeply acquainted with them, as the Flat Assembler does all the hard work for us and all we have to do is tell it which format we are interested in (and format our code accordingly). We will use a compile time variable, ACTIVE_TARGET, for conditional compilation and use the following constants as possible values:
; Put this in the beginning of 'platform.inc'
type_dll equ 0
type_obj equ 1
platform_w32 equ 2
platform_w64 equ 4
platform_l32 equ 8
platform_l64 equ 16
TARGET_W32_DLL equ platform_w32 or type_dll
TARGET_W32_OBJ equ platform_w32 or type_obj
TARGET_W64_DLL equ platform_w64 or type_dll
TARGET_W64_OBJ equ platform_w64 or type_obj
TARGET_L32_O equ platform_l32 or type_obj
TARGET_L64_O equ platform_l64 or type_obj