FreshLib provides a powerful set of macros that simplify assembly programming by handling common patterns like procedure definitions, data declarations, and calling conventions. This tutorial covers the essential macros used throughout FreshLib and AsmBB.
Topics Covered
Procedure Macros - proc, endp, begin, return
Data Declaration - iglobal, uglobal, endg, text
Calling Convention - stdcall, invoke
Structure Definitions - struct, rstruct, ends
Initialization - InitializeAll, FinalizeAll
Hash Tables - PHashTable, phash
Procedure Macros
proc / endp / begin / return
The proc macro defines a procedure with automatic stack frame management:
Parameters MUST start with a dot (.param1, .param2)
begin sets up the stack frame (push ebp; mov ebp, esp)
return restores the stack and returns (leave; ret)
Local variables use negative offsets from EBP
Local Variables
proc Example, .input
.localVar dd ? ; Local variable (4 bytes)
.buffer rb 256 ; Local buffer (256 bytes)
begin
mov [.localVar], 42
return
endp
Local variables are defined BEFORE begin and AFTER the parameter list.
Data Declaration Macros
iglobal / uglobal / endg
These macros separate initialized and uninitialized data:
; Initialized data (goes into .data section)
iglobal
cMessage text "Hello, World!", 13, 10
nVersion dd 100
endg
; Uninitialized data (goes into .bss section, no space in binary)
uglobal
hBuffer dd ?
szTempPath rb 256
endg
AsmBB Usage Example (from version.asm):
iglobal
cVersion text VERSION_STRING
endg
text Macro
Creates zero-terminated strings with optional escape sequences:
iglobal
cHeader text "Content-Type: text/html", 13, 10, 13, 10
cError text "Error: ", 0
endg