home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / priac1.zip / PRIAC1.ASM < prev    next >
Assembly Source File  |  1988-09-27  |  6KB  |  181 lines

  1. comment    |
  2.  
  3.     This program reads and reports the current contents of the Inter-
  4.     Application Communications Area (IAC).
  5.  
  6.     The IAC is 16 bytes beginning at addr 0040:00F0h. Any program can
  7.     write information to the IAC for another program to read. Please
  8.     note: unless the first program directly    invokes the second program,
  9.     it cannot protect the IAC from being altered by an intervening program.
  10.     The IAC can be used, for instance, to pass an address from one program
  11.     to the next.
  12.  
  13.     Written for MASM 5.0 by Hardin Brothers for PCResource. The original
  14.     appeared in the April 1988 issue of their magazine. Entire contents of
  15.     the April 1988 issue (C) Copyright 1988 by
  16.                 IDG Communications/Peterborough, Inc.
  17.  
  18.     Hardin Brothers is a freelance programmer and technical writer. Write
  19.     to him at 280 N. Campus Ave., Upland, CA  91786. Enclose a self-
  20.     addressed, stamped envelope for a reply.
  21.  
  22. v1.1, 27 Sep 88 Toad Hall Tweak
  23. - Converted to .COM format
  24. - Adding a little local buffer so we can move the entire IAC buffer in
  25.   locally.
  26. - Convert entire IAC area data into hex, THEN display it.
  27. - Using LODSB and STOSB for snarfing bytes from IAC, then stuffing
  28.   to our buffer.
  29. - Learned something about the XLAT instruction (how to override the
  30.   expected DS: segment)!  By the way, unless you're doing an override,
  31.   you don't HAVE to specify BX ("xlat bx").  "xlat" is just fine.
  32.   BX is unchanged, so you don't HAVE to reload it each call.
  33. - Adding a little test:  stuff a message in the IAC area for the
  34.   NEXT time we run this program!  Gives us something to read beside
  35.   0's.
  36. David Kirschbaum
  37. Toad Hall
  38. kirsch@braggvax.ARPA
  39.  
  40.     |
  41.  
  42. LF    equ    0Ah        ; linefeed char
  43. CR    equ    0Dh        ; carriage return char
  44. STDOUT    equ    1        ; standard output device
  45. IACLEN    equ    10H        ; IAC buffer is 16 bytes long        v1.1
  46.  
  47. EXIT    macro    val
  48. ;    mov    AH, 4Ch        ; INT 21h service 4Ch: exit from program
  49. ;                ; also returns a value. replaces old INT 20h.
  50. ;    mov    AL, val        ; return value byte
  51.     mov    ax,4C00H + val    ; faster as a word            v1.1
  52.     int    21h
  53.     endm
  54.  
  55. Cseg    SEGMENT PUBLIC PARA 'Code'        ;            v1.1
  56.     ASSUME    CS:Cseg, DS:Cseg, ES:Cseg    ;            v1.1
  57.  
  58.     org    100H                ;            v1.1
  59.  
  60. start    proc    near            ;                v1.1
  61.     mov    DX, offset title$    ; addr DS:DX points to output    v1.1
  62.                     ; string            v1.1
  63.     mov    CX, LTITLE        ; output string byte count
  64.     mov    BX, STDOUT        ; write to standard output device
  65.     mov    AH, 40h            ; service 40h: write to file/device
  66.     int    21h
  67.  
  68.     mov    AX, 0040h        ; BIOS information segment
  69.     mov    DS,ax            ; Initialize for snarfing    v1.1
  70.     ASSUME    DS:Nothing        ; Just to be neat        v1.1
  71.  
  72.     mov    SI, 0F0h        ; DS:si = start of IAC
  73.     call    Hexify            ; Hexify into hexbuff, display    v1.1
  74.  
  75. ;v1.1 Some new fiddling:
  76. ;First move the entire IAC buffer into our local iacbuff and play with it.
  77. ;Then move some local data into the IAC buffer and do it again.
  78.  
  79.     call    Snarf_IAC        ; Move IAC data into local buffer
  80.  
  81.     push    DS            ; save that 40H IAC segment
  82.     mov    ax,CS
  83.     mov    DS,ax
  84.     ASSUME    DS:CSeg,ES:Cseg        ; Now working in local buffers
  85.  
  86.     mov    si,offset iacbuff    ; Hexify the local buffer this time
  87.     call    Hexify            ; Hexify DS:si and display it.
  88.  
  89.     pop    ES            ; ES = IAC segment
  90.     mov    si,offset title$ +2    ; Move our little intro text
  91.     mov    di,0F0H            ; ES:di = vector to IAC buffer
  92.     mov    cx,IACLEN SHR 1        ; IAC buffer length in words
  93.     rep    movsw            ; Move our text into the IAC
  94.  
  95.     mov    ax,CS
  96.     mov    ES,ax            ; ES = our code segment again
  97.  
  98.     call    Snarf_IAC        ; Move the new IAC buffer back in
  99.     mov    dx,offset iacbuff    ; our buffer
  100.     mov    cx,IACLEN        ; nr bytes to write
  101.     mov    BX, STDOUT        ; write to standard output device
  102.     mov    AH, 40h            ; service 40h: write to file/device
  103.     int    21h
  104.  
  105.     EXIT    0            ; normal termination value
  106. Start    endp
  107.  
  108. Snarf_IAC    proc    near        ;                v1.1
  109.     push    DS
  110.     mov    ax, 0040H        ; BIOS data area
  111.     mov    DS,ax
  112.     mov    SI, 0F0h        ; DS:si = start of IAC
  113.     mov    CX, IACLEN SHR 1    ; length of IAC in words
  114.     mov    di, offset iacbuff    ; ES:di = local buffer
  115.     rep    movsw            ; move it in
  116.     pop    DS
  117.     ret
  118. Snarf_IAC    endp
  119.  
  120.  
  121.     ASSUME    DS:Nothing        ;a reminder            v1.1
  122.  
  123. ;Enter with DS:si pointing to buffer you wish hexified.            v1.1
  124. Hexify    proc    near            ;                v1.1
  125.     mov    di, offset hexbuff    ; ES:di = hex buffer        v1.1
  126.     mov    BX,offset hexasc    ; DS:BX points to ASCII        v1.1
  127.     mov    cx,IACLEN        ; nr bytes to hexify        v1.1
  128.     cld                ; insure forward        v1.1
  129. lp:
  130.     lodsb                ; Get a byte from DS:si        v1.1
  131.     call    Convert            ; convert bytes to ASCII hex,
  132.                     ; stuff in hex buffer        v1.1
  133.     loop    lp            ; continue loop
  134.     mov    ax,0A0DH        ; Terminate hex string with CR/LF v1.1
  135.     stosw
  136.     push    DS            ; Save DS a sec            v1.1
  137.     mov    ax,CS            ;                v1.1
  138.     mov    DS,ax            ;                v1.1
  139.     ASSUME    DS:Cseg            ;                v1.1
  140.  
  141.     mov    cx,di            ; string end +1            v1.1
  142.     mov    dx,offset hexbuff    ; hex string to display        v1.1
  143.     sub    cx,dx            ; - start = chars to display    v1.1
  144.     mov    BX, STDOUT        ; write to standard output device
  145.     mov    AH, 40h            ; service 40h: write to file/device
  146.     int    21h
  147.     pop    DS            ; restore DS            v1.1
  148.     ret
  149. Hexify    endp                ;                v1.1
  150.  
  151. Convert    proc    near            ;                v1.1
  152.     mov    dx,cx            ; preserve cx loop counter    v1.1
  153.     mov    AH, AL            ; keep copy of byte
  154.     mov    CL, 4            ; set nibble count
  155.     shr    AL, CL            ; move top nibble down
  156.     xlat    CS:[bx]            ; translate nibble to hex char v1.1
  157.     stosb                ; store Hex char        v1.1
  158.     mov    AL, AH            ; restore byte
  159.     and    AL, 0Fh            ; mask top nibble
  160.     xlat    CS:[bx]            ; translate            v1.1
  161.     stosb                ; store char            v1.1
  162.     mov    ax,' h'            ; 'h ', reversed        v1.1
  163.     stosw                ; store in the string        v1.1
  164.     mov    cx,dx            ; restore cx            v1.1
  165.     ret
  166. Convert    endp                ;                v1.1
  167.  
  168. hexasc    db    '0123456789ABCDEF'
  169.  
  170. title$    db    CR, LF
  171.     db    'Contents of Inter-Application Communication Area'
  172.     db    ' (IAC):', CR, LF, CR, LF
  173. LTITLE    equ    $-title$
  174.  
  175. iacbuff equ    $            ;move IAC buffer into here    v1.1
  176.                     ;for processing (16 bytes long)    v1.1
  177. hexbuff    equ    iacbuff + IACLEN    ;buffer to build hex string    v1.1
  178.  
  179. Cseg    ends
  180.     end    start
  181.