home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 11 / hello.asm next >
Encoding:
Assembly Source File  |  1988-08-11  |  3.0 KB  |  100 lines

  1. ;
  2. ; Name:          hello
  3. ;
  4. ; Description:   This RAM-resident (terminate-and-stay-resident) utility
  5. ;                displays the message "Hello, World" in response to a
  6. ;                software interrupt.
  7. ;
  8. ; Comments:      Assemble and link to create HELLO.EXE.
  9. ;
  10. ;                Execute HELLO.EXE to make resident.
  11. ;
  12. ;                Execute  INT 64h  to display the message.
  13. ;
  14.  
  15.  
  16. TSRInt           EQU     64h
  17. STDOUT           EQU     1
  18.  
  19. RESIDENT_TEXT    SEGMENT byte public 'CODE'
  20.                  ASSUME  cs:RESIDENT_TEXT,ds:RESIDENT_DATA
  21.  
  22. TSRAction        PROC    far
  23.  
  24.                  sti                    ; enable interrupts
  25.  
  26.                  push    ds             ; preserve registers
  27.                  push    ax
  28.                  push    bx
  29.                  push    cx
  30.                  push    dx
  31.  
  32.                  mov     dx,seg RESIDENT_DATA
  33.                  mov     ds,dx
  34.                  mov     dx,offset Message      ; DS:DX -> message
  35.                  mov     cx,16                  ; CX = length
  36.                  mov     bx,STDOUT              ; BX = file handle
  37.                  mov     ah,40h                 ; AH = INT 21h function 40h
  38.                                                 ; (Write File)
  39.                  int     21h                    ; display the message
  40.  
  41.                  pop     dx                     ; restore registers and exit
  42.                  pop     cx
  43.                  pop     bx
  44.                  pop     ax
  45.                  pop     ds
  46.                  iret
  47.  
  48. TSRAction        ENDP
  49.  
  50. RESIDENT_TEXT    ENDS
  51.  
  52.  
  53. RESIDENT_DATA    SEGMENT word public 'DATA'
  54.  
  55. Message          DB      0Dh,0Ah,'Hello, World',0Dh,0Ah
  56.  
  57. RESIDENT_DATA    ENDS
  58.  
  59.  
  60. TRANSIENT_TEXT   SEGMENT para public 'TCODE'
  61.                  ASSUME  cs:TRANSIENT_TEXT,ss:TRANSIENT_STACK
  62.  
  63. HelloTSR PROC    far                    ; At entry:     CS:IP -> SnapTSR
  64.                                         ;               SS:SP -> stack
  65.                                         ;               DS,ES -> PSP
  66. ; Install this TSR's interrupt handler
  67.  
  68.                  mov     ax,seg RESIDENT_TEXT
  69.                  mov     ds,ax
  70.                  mov     dx,offset RESIDENT_TEXT:TSRAction
  71.                  mov     al,TSRInt
  72.                  mov     ah,25h
  73.                  int     21h
  74.  
  75. ; Terminate and stay resident
  76.  
  77.                  mov     dx,cs          ; DX = paragraph address of start of
  78.                                         ; transient portion (end of resident
  79.                                         ; portion)
  80.                  mov     ax,es          ; ES = PSP segment
  81.                  sub     dx,ax          ; DX = size of resident portion
  82.  
  83.                  mov     ax,3100h       ; AH = INT 21h function number (TSR)
  84.                                         ; AL = 00H (return code)
  85.                  int     21h
  86.  
  87. HelloTSR         ENDP
  88.  
  89. TRANSIENT_TEXT   ENDS
  90.  
  91.  
  92. TRANSIENT_STACK  SEGMENT word stack 'TSTACK'
  93.  
  94.                  DB      80h dup(?)
  95.  
  96. TRANSIENT_STACK  ENDS
  97.  
  98.  
  99.                  END     HelloTSR
  100.