; MASM /DVERSION=x /DTEXTE=y MACROS
; mit x=1,2,3,4 und y=1,2,3
; .lall  ; Makroexpansion im Listing (Default)
; .sall  ; Keine Makroexpansion im Listing

IF VERSION EQ 1
OUTCHAR MACRO
        MOV AH,2
        INT 21h
        ENDM
INCHAR  MACRO
        MOV AH,1
        INT 21h
        ENDM
ENDIF

IF VERSION EQ 2
OUTCHAR MACRO
        PUSH AX
        MOV AH,2
        INT 21h
        POP AX
        ENDM
INCHAR  MACRO
        PUSH BX
        MOV BH,AH
        MOV AH,1
        INT 21h
        MOV AH,BH
        POP BX
        ENDM
ENDIF

IF VERSION EQ 3
OUTCHAR MACRO CHAR
        PUSH AX
        PUSH DX
        MOV AH,2
; Problem falls AH an CHAR uebergeben wird
        MOV DL,CHAR
        INT 21h
        POP DX
        POP AX
        ENDM
INCHAR  MACRO CHAR
        PUSH AX
        MOV AH,1
        INT 21h
        MOV CHAR,AL
        POP AX
; Problem falls AL oder AH an CHAR uebergeben wird
        ENDM
ENDIF

IF VERSION EQ 4
OUTCHAR MACRO CHAR
        PUSH AX
        PUSH DX
        MOV DL,CHAR
        MOV AH,2
        INT 21h
        POP DX
        POP AX
        ENDM
INCHAR  MACRO CHAR
        IF ("&CHAR&" NE "AL") AND ("&CHAR&" NE "AH")
        PUSH AX
        MOV AH,1
        INT 21h
        MOV CHAR,AL
        POP AX
        ELSE
        PUSH BX
        PUSH AX
        MOV AH,1
        INT 21h
        MOV BL,AL
        POP AX
        MOV CHAR,BL
        POP BX
        ENDIF
        ENDM
ENDIF

OUTSTR MACRO STR
       PUSH DS
       PUSH AX
       PUSH DX
       MOV AX,SEG STR
       MOV DS,AX
       MOV DX,OFFSET STR
       MOV AH,9
       INT 21h
       POP DX
       POP AX
       POP DS
       ENDM

OUTCSTR MACRO STR
LOCAL CSTR,_CSTR
        PUSH DS
        PUSH AX
        PUSH DX
        PUSH CS
        POP DS
        MOV DX,OFFSET CSTR
        MOV AH,9
        INT 21h
        POP DX
        POP AX
        POP DS
        JMP _CSTR       
CSTR    DB ">>&STR&<<$"
_CSTR:   
        ENDM

REGSAVE MACRO
        IRP REGS,<AX,BX,CX,DX,SI,DI>
        PUSH REGS
        ENDM
        ENDM

REGREST MACRO
        IRP REGS,<DI,SI,DX,CX,BX,AX>
        POP REGS
        ENDM
        ENDM

CRLF MACRO
     REGSAVE
     MOV AH,2
     MOV DL,13
     INT 21h
     MOV DL,10
     INT 21h
     REGREST
     ENDM

STOP MACRO
     MOV AX,4C00h
     INT 21h
     ENDM

CSEG SEGMENT
     ASSUME CS:CSEG,DS:DSEG

MAIN PROC
     MOV AX,DSEG
     MOV DS,AX
IF (VERSION EQ 1) OR (VERSION EQ 2)
     INCHAR
     MOV DL,AL
     OUTCHAR
ENDIF
IF VERSION EQ 3
     OUTCHAR '>'
     INCHAR BL
     OUTCHAR BL
     OUTCHAR '<'
ENDIF
IF VERSION EQ 4
     OUTCHAR '>'
     INCHAR AH
     OUTCHAR AH
     INCHAR AL
     OUTCHAR AL
     OUTCHAR '<'
ENDIF
IF TEXTE EQ 1
     CRLF
     MOV AH,9
     MOV DX,OFFSET TAF
     INT 21h
ENDIF
IF TEXTE EQ 2
     CRLF
     OUTSTR TAF
ENDIF
IF TEXTE EQ 3
     CRLF
     OUTCSTR <Moin Moin>
     CRLF
     OUTSTR TAF
     CRLF
     OUTCSTR <Really :-)>
ENDIF
     STOP
MAIN ENDP

CSEG ENDS

DSEG SEGMENT
TAF  DB "Thats all folks$"
DSEG ENDS

SSEG SEGMENT STACK
     DW 128 DUP (?)
SSEG ENDS

     END MAIN