|
ENUM - A NASM macro emulating the C ENUM command |
|
Written by Mammon
|
ENUM
by mammon_
;Summary: A NASM macro emulating the C 'ENUM" command
;Assembler: NASM
%macro ENUM 2-* ;Usage: ENUM int SYMBOLS
%assign i %1 ; where int is the number to begin enumeration at [0]
%rep %0 ; SYMBOLS is a list of Symbols to define
%2 EQU 0xi ;Example: ENUM 0 TRUE FALSE
%assign i i+1 ; this EQUates TRUE to 0 and FALSE to 1
%rotate 1 ;Example: ENUM 11 JACK QUEEN KING
%endrep ; this EQUs JACK to 11, QUEEN to 12, KING to 13
%endmacro
CallTable
by mammon_
;Summary: Error Handler to demonstrate call-tables
;Compatibility:
;Notes: The EQUs define offsets from the start of ErrorHandler. Thus,
; ERROR_FILE_NOT_FOUND is at offset 0, ERROR_FILE_READ_ONLY is
; at offset 4 ( one dword from offset 0), etc.
; Each entry in the call table contains the address of the
; code label listed there...so, in order, ErrorHandler contains
; the addresses for the functions ERROR1, ERROR2, ERROR3, and
; ERROR4.
; The code to call an error handler uses as its base
; call [Errorhandler]
; or, call the function whose address is stored at location
; ErrorHandler. By adding the EQUs to this base, one gets the
; offset for each function within ErrorHandler.
ERROR_FILE_NOT_FOUND EQU 0
ERROR_FILE_READ_ONLY EQU 4
ERROR_DISK_FULL EQU 8
ERROR_UNKNOWN EQU 12
ErrorHandler:
;------------ Here lies the Call-Table
DWORD ERROR1
DWORD ERROR2
DWORD ERROR3
DWORD ERROR4
;------------ Here ends the Call-Table
;Handlers for various errors; offsets to these are stored in the Call-Table
ERROR1:
...Code to Create File...
ret
ERROR2:
...Code to CHMOD File...
ret
ERROR3:
...Code to Display Disk Full Message...
jmp Exit_Program
ERROR4:
...Code to Display Unknown System Error-Code...
jmp Exit_Program
;Code to call Various errors
call dword ptr [ErrorHandler + ERROR_FILE_NOT_FOUND]
call dword ptr [ErrorHandler + ERROR_FILE_READ_ONLY]
jmp dword ptr [ErrorHandler + ERROR_FILE_DISK_FULL]
jmp dword ptr [ErrorHandler + ERROR_FILE_UNKNOWN]
|