home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / XLIB40.ZIP / EXAMP1B.ASM < prev    next >
Assembly Source File  |  1994-02-18  |  3KB  |  81 lines

  1. ;This program is the TASM version of the MASM pogram in Example 1 of the XLIB
  2. ;documentation.  TASM programs must resize the DOS memory block in which they
  3. ;are contained so that there will be some free memory for allocation by
  4. ;INITXLIB.  The initialization code for the program below determines the size
  5. ;of the program from the facts that at startup, ES:0000 will equal the address
  6. ;of the program segment prefix, and SS:SP will equal the terminal address of
  7. ;the program.
  8.  
  9.                MASM51                        ;Use MASM 5.1 compatibility mode
  10.                QUIRKS                        ;Allow MASM 5.1 quirks
  11.  
  12. PUSHW          MACRO IMMEDIATE16:REST        ;Macro to PUSH 16-bit contant
  13.                IF (@WordSize EQ 4)
  14.                DB             66H
  15.                ENDIF
  16.                DB             68H
  17.                DW             IMMEDIATE16
  18.                ENDM
  19.  
  20. PUSHD          MACRO IMMEDIATE32:REST        ;Macro to PUSH 32-bit constant
  21.                IF (@WordSize EQ 2)
  22.                DB             66H
  23.                ENDIF
  24.                DB             68H
  25.                DD             IMMEDIATE32
  26.                ENDM
  27.  
  28.                .MODEL        LARGE,PASCAL
  29.                .386P
  30.                DOSSEG                        ;Place stack at highest address
  31.  
  32.                INCLUDE        XLIBB.INC      ;Include XLIBB public symbols
  33.                INCLUDELIB     XLIBB.LIB      ;Link with XLIBB.LIB
  34.  
  35.                .STACK         1024
  36.                .CODE
  37.                .STARTUP
  38.                MOV            AX,SP          ;Resize program memory block
  39.                SHR            AX,4
  40.                MOV            BX,SS
  41.                ADD            BX,AX
  42.                INC            BX             ;BX = first para. beyond program
  43.                MOV            AX,ES
  44.                SUB            BX,AX          ;BX = program size in paragraphs
  45.                MOV            AH,4AH         ;Resize memory block at ES:0000
  46.                INT            21H
  47.                JC             MAINEXIT       ;Failed to resize
  48.  
  49.                CALL           INITXLIB       ;Initialize XLIB
  50.                OR             EAX,EAX        ;EAX = 0 if successful
  51.                JNZ            MAINEXIT
  52.  
  53. INITDONE:      PUSHD          OFFSET DEMOPROC
  54.                CALL           CALLPM         ;Execute DEMOPROC in protected
  55. MAINEXIT:      MOV            AX,4C00H       ;DOS termination function
  56.                INT            21H
  57.  
  58. ;Protected-mode routines must be placed in following segment:
  59. TSEG           SEGMENT PARA PUBLIC USE32 'CODE'
  60.                ASSUME CS:TSEG, SS:TSEG, DS:TSEG, ES:TSEG, FS:DSEG, GS:DGROUP
  61.  
  62.                LARGESTACK
  63.  
  64. ;Protected-mode routine to print message to the screen using DOS function.
  65. DEMOPROC       PROC NEAR
  66.                MOV            EBX,OFFSET PMMSG
  67.                MOV            AH,02H
  68. MSGLOOP:       MOV            DL,CS:[EBX]    ;32-bit offset!!!!!
  69.                OR             DL,DL
  70.                JZ             EXIT
  71.                INT            21H            ;Print character with DOS
  72.                INC            EBX
  73.                JMP            MSGLOOP
  74. EXIT:          RET                           ;Go back to real or V86 mode
  75. PMMSG          DB  "In 32-bit protected mode!!!  "
  76.                DB  "Returning to real mode.",10,13,0
  77. DEMOPROC       ENDP
  78.  
  79. TSEG           ENDS
  80.                END
  81.