; MACRO.INC -- Generic set of macros and equates. ; This file is free for anyone to use and enhance. ; To use, insert as the first line in your ASM file, and ; following (after) any EQU directives. ; If used in the main ASM file, use as shown below: ; ; dosseg ; ; cr equ 0dh ; ; include macro.inc ; ; .stack 512d ;Default = 1024d. ; ; .data? ; .............. ; .data ; .............. ; .code ; .............. ; ; Created by: James Webster ; 113 Riverview Drive ; Lafollette, TN 37766 ; EMAIL: jwebste3@bellsouth.net ; ;; The .model directive must be the very 1st line. .model small ;Choose the desired memory model. ;.model medium ;.model large ;.model huge ;; The next lines need to be any other .INC or .EQU files that are needed. ;include help.equ ;For binary file created by DAT2BIN.EXE. .xlist ;Turn off list-file generation. ;; Define our global equates. cr equ 0dh escc equ 1bh bs equ 08h ctrl_c equ 3 ctrl_e equ 5 ;; Simplify some commonly used directives. ;; Example of use: ;; ---------------------------------------- bptr equ byte ptr ;; cmp es:bptr [si], 0e5h wptr equ word ptr ;; cmp es:wptr [si], 0e5e5h dptr equ dword ptr ;; call es:dptr [si] fptr equ far ptr ;; call fptr procedure_name nptr equ near ptr ;; call nptr procedure_name .sall ;Don't show macro contents. ;; Now define a few macros to make our job of coding easier and ;; to make our .ASM files a little smaller and easier to read. ;; Example of use: ;; ------------------------------------------------------------------------ ;;.data ;; extb flag_byte, char_attr, .... (Up to 11 variables per line.) ;; extb macro a,b,c,d,e,f,g,h,i,j,k irp xx, ifnb extrn xx:byte else exitm endif endm endm ;; Example of use: ;; ------------------------------------------------------------------------ ;;.data ;; extw flag_word, video_seg, .... (Up to 11 variables per line.) ;; extw macro a,b,c,d,e,f,g,h,i,j,k irp xx, ifnb extrn xx:word else exitm endif endm endm ;; Example of use: ;; ------------------------------------------------------------------------ ;;.data ;; extd oldint09, oldint1c, .... (Up to 11 variables per line.) ;; extd macro a,b,c,d,e,f,g,h,i,j,k irp xx, ifnb extrn xx:dword else exitm endif endm endm ;; Example of use: ;; ------------------------------------------------------------------------ ;;.code ;; extp procname1, procname2, .... (Up to 11 procedures per line.) ;; extp macro a,b,c,d,e,f,g,h,i,j,k irp xx, ifnb extrn xx:proc else exitm endif endm endm ;; Example of use: ;; ------------------------------------------------------------------------ ;;.code ;; extn nearproc1, nearproc2, .... (Up to 11 procedures per line.) ;; extn macro a,b,c,d,e,f,g,h,i,j,k irp xx, ifnb extrn xx:near else exitm endif endm endm ;; Example of use: ;; ------------------------------------------------------------------------ ;;.code ;; extf farproc1, farproc2, .... (Up to 11 procedures per line.) ;; extf macro a,b,c,d,e,f,g,h,i,j,k irp xx, ifnb extrn xx:far else exitm endif endm endm ;; Example of use: ;; ------------------------------------------------------------------------ ;;.code ;; ;; dummy_proc proc ;; pushr ;(Up to 11 registers per line.) ;; ...... :Code goes here. ;; popr ;; ret ;; dummy_proc endp ;; pushr macro a,b,c,d,e,f,g,h,i,j,k irp xx, ifnb push xx else exitm endif endm endm popr macro a,b,c,d,e,f,g,h,i,j,k irp xx, ifnb pop xx else exitm endif endm endm ;; Example of use: ;; ------------------------------------------------------------------------ ;;.code ;; ;; dummy_proc proc ;; pushad ;; ...... :Code goes here. ;; popad ;; ret ;; dummy_proc endp ;; pushad macro push ax push bx push cx push dx endm popad macro pop dx pop cx pop bx pop ax endm ;; Example of use: ;; ------------------------------------------------------------------------ ;;.code ;; ;; dummy_proc proc ;; pushall ;; ...... :Code goes here. ;; popall ;; ret ;; dummy_proc endp ;; pushall macro push ax push bx push cx push dx push di push si push bp push ds push es endm popall macro pop es pop ds pop bp pop si pop di pop dx pop cx pop bx pop ax endm ;; Example of use: ;; ---------------------------------------- jmps macro n ;; jmps label_name jmp short n ;; Jump must not exceed 128 bytes forward endm ;; or 127 bytes backward. ;; Example of use: ;; ------------------------------------------------------------------------ ;;.data ;; call_table label byte ;; dso proc_name1 ;Only one procedure name per line. ;; dso proc_name2 ; This is a good macro to use for call ;; ; or jump tables that require long (FAR) ;; ; address pointers. dso macro n dw offset n dw seg n endm ;; Example of use: ;; ---------------------------------------- shrr macro reg,count ;; shrr bx,4 ;Divide BX by 16. rept count shr reg,1 endm endm ;; Example of use: ;; ---------------------------------------- shlr macro reg,count ;; shlr bx,4 ;Multiply BX by 16. rept count shl reg,1 endm endm ; Factor = 1 2 3 4 5 6 7 8 ; ------------------------------------------------------------------- ; Power of 2 = 2 4 8 16 32 64 128 256 shmul macro factor ;;On entry DX:AX = value to multiply. rept factor ;;FACTOR = a power of 2. shl ax,1 ;;Example: DX:AX * 8 = shmul 3 rcl dx,1 endm endm shdiv macro factor ;;On entry DX:AX = value to divide. rept factor ;;FACTOR = a power of 2. shr dx,1 ;;Example: DX:AX / 8 = shdiv 3 rcr ax,1 endm endm ;--------------------------------------------------------------------; ; The below allows the use of the SHL instruction to multiply a ; ; 16-bit value by a quotient that is not a power of 2. In all ; ; cases: REG1 is the primary register that holds the value to be ; ; multiplied and that returns the sum. REG2 is the general work ; ; register. SH?? is the macro name and ?? is the "multiply by" value.; ;--------------------------------------------------------------------; ;; Example of use: ;; --------------------------- sh3 macro reg1,reg2 ;; sh3 ax,dx mov reg2,reg1 ;;Place copy of value in REG2. shl reg1,1 ;;Multiply REG1 by 2. add reg1,reg2 ;;REG1 = REG1 + REG2 endm sh6 macro reg1,reg2 mov reg2,reg1 ;;Place copy of value in REG2. shl reg1,1 ;;Multiply REG1 by 4. shl reg1,1 shl reg2,1 ;;Multiply REG2 by 2. add reg1,reg2 ;;REG1 = REG1 + REG2 endm sh10 macro reg1,reg2 mov reg2,reg1 ;;Place copy of value in REG2. shl reg1,1 ;;Multiply REG1 by 8. shl reg1,1 shl reg1,1 shl reg2,1 ;;Multiply REG2 by 2. add reg1,reg2 ;;REG1 = REG1 + REG2 endm sh12 macro reg1,reg2 mov reg2,reg1 ;;Place copy of value in REG2. shl reg1,1 ;;Multiply REG1 by 8. shl reg1,1 shl reg1,1 shl reg2,1 ;;Multiply REG2 by 4. shl reg2,1 add reg1,reg2 ;;REG1 = REG1 + REG2 endm sh20 macro reg1,reg2 mov reg2,reg1 ;;Place copy of value in REG2. shl reg1,1 ;;Multiply REG1 by 16. shl reg1,1 shl reg1,1 shl reg1,1 shl reg2,1 ;;Multiply REG2 by 4. shl reg2,1 add reg1,reg2 ;;REG1 = REG1 + REG2 endm sh24 macro reg1,reg2 mov reg2,reg1 ;;Place copy of value in REG2. shl reg1,1 ;;Multiply REG1 by 16. shl reg1,1 shl reg1,1 shl reg1,1 shl reg2,1 ;;Multiply REG2 by 8. shl reg2,1 shl reg2,1 add reg1,reg2 ;;REG1 = REG1 + REG2 endm sh36 macro reg1,reg2 mov reg2,reg1 ;;Place copy of value in REG2. shl reg1,1 ;;Multiply REG1 by 32. shl reg1,1 shl reg1,1 shl reg1,1 shl reg1,1 shl reg2,1 ;;Multiply REG2 by 4. shl reg2,1 add reg1,reg2 ;;REG1 = REG1 + REG2 endm sh48 macro reg1,reg2 mov reg2,reg1 ;;Place copy of value in REG2. shl reg1,1 ;;Multiply REG1 by 32. shl reg1,1 shl reg1,1 shl reg1,1 shl reg1,1 shl reg2,1 ;;Multiply REG2 by 16. shl reg2,1 shl reg2,1 shl reg2,1 add reg1,reg2 ;;REG1 = REG1 + REG2 endm .list ;End of MACRO.INC