Annotation of os2sdk/demos/examples/dynlink/dynlib3.asm, revision 1.1.1.1

1.1       root        1: 
                      2: ; dynlib3.asm
                      3: ;
                      4: ;   Created 17 August 1987 by Kevin Ruddell, Microsoft Corp
                      5: ;
                      6: ;
                      7: ; Demonstrates the use of shared and non-shared data segments.
                      8: ; When each process attaches, the contents of "count" (in a shared segment)
                      9: ; is incremented and assigned to "id" (in a non-shared segment).
                     10: ; "count" is used to detect the first time the initialization routine
                     11: ; is invoked.
                     12: ; When a process makes a call to PRINTDATA, the current values of
                     13: ; "count" and "id" are displayed on the screen.  They will be different for
                     14: ; all but the last process to attach to the dll.
                     15: 
                     16: 
                     17:        TITLE   dynlib3
                     18: 
                     19:        .286p
                     20: 
                     21: EXTRN  DOSWRITE:FAR
                     22: 
                     23: ;-----------------------------------------------------------------------------
                     24: ;A fresh copy of this segment is created for each process attaching to the dll.
                     25: 
                     26: ETHEL  SEGMENT  WORD PUBLIC 'FAR_DATA'
                     27: id         DW      00H             ;unique to each attached process
                     28: ETHEL  ENDS
                     29: 
                     30: ;---------------------------------------
                     31: ;This segment is shared by all processes attached to the dll.
                     32: 
                     33: FRED   SEGMENT  WORD PUBLIC 'FAR_DATA'
                     34: First      DB      'First time initialization.',  0aH,  0dH,  00H
                     35: NotFirst    DB     'Not first time initialization.',  0aH,  0dH,  00H
                     36: msg_beg     DB     'I am number ',  00H
                     37:     ORG     $+1     ;to line up on word boundaries
                     38: const_1     DB     '.',  0aH,  0dH,  00H
                     39: msg_mid     DB     '.  There are ',  00H
                     40: count      DW      00H             ;number of processes which have attached
                     41: msg_end     DB     ' processes attached.',  0dH,  00H
                     42: written     DW     00H             ;bytes written
                     43: c          DW      00H             ;temporary variable
                     44: FRED   ENDS
                     45: 
                     46: ;-----------------------------------------------------------------------------
                     47: ;-----------------------------------------------------------------------------
                     48:        ASSUME  CS: _TEXT, DS: FRED, ES: ETHEL
                     49: ;---------------------------------------
                     50: _TEXT  SEGMENT BYTE PUBLIC 'CODE'
                     51: ;---------------------------------------
                     52: ; START
                     53: ; Initialization routine.
                     54: ; Called for each process when the process attaches to the dll.
                     55: ;
                     56: ; count is initialized to 0 in its definition, and so can be used as a first-
                     57: ; time switch. A First/NotFirst message is sent to the screen and count is
                     58: ; incremented to reflect the number of processes which have attached to
                     59: ; the dll.  The freshly-incremented count is copied to the non-shared
                     60: ; location id and is unique among the attached processes.  Actually,
                     61: ; accesses to count should be synchronized, but this is omitted for simplicity.
                     62: ; The unique id is sent to the screen.
                     63: 
                     64: 
                     65: START  PROC    FAR
                     66: 
                     67:        push    di                  ;save registers
                     68:        push    si
                     69:        push    ds
                     70:        push    es
                     71: 
                     72:        mov     ax,SEG FRED         ;set up segment registers
                     73:        mov     ds,ax               ;ds points to global segment
                     74:        mov     ax,SEG ETHEL
                     75:        mov     es,ax               ;es points to non-shared segment
                     76: 
                     77:        mov     ax,count
                     78:        inc     WORD PTR count      ;bump shared count of attached processes
                     79:        cmp     ax,0                ;test for first time through
                     80:        jne     START_NOT
                     81: 
                     82:        push    1                   ;write to standard output (screen)
                     83:        push    ds
                     84:        push    OFFSET First        ;address of "First time initialization."
                     85:        push    28                  ;number of bytes to write
                     86:        push    ds
                     87:        push    OFFSET written      ;address to hold # bytes written
                     88:        call    FAR PTR DOSWRITE    ;synchronous write
                     89:        jmp     START_ID
                     90: 
                     91: START_NOT:
                     92:        push    1                   ;write to standard output
                     93:        push    ds
                     94:        push    OFFSET NotFirst     ;addr of "Not first time initialization."
                     95:        push    32                  ;number of bytes to write
                     96:        push    ds
                     97:        push    OFFSET written      ;address to hold # bytes written
                     98:        call    FAR PTR DOSWRITE    ;synchronous write
                     99: 
                    100: START_ID:
                    101:        mov     ax,count            ;non-shared id = shared count
                    102:        mov     es:id,ax
                    103: 
                    104:        push    1                   ;write to standard output
                    105:        push    ds
                    106:        push    OFFSET msg_beg      ;addr of "I am number "
                    107:        push    12                  ;number of bytes to write
                    108:        push    ds
                    109:        push    OFFSET written      ;address to hold # bytes written
                    110:        call    FAR PTR DOSWRITE    ;synchronous write
                    111: 
                    112:        mov     al,BYTE PTR count
                    113:        add     al,'0'              ;c = count + '0'
                    114:        mov     BYTE PTR c,al
                    115: 
                    116:        push    1                   ;write to standard output
                    117:        push    ds
                    118:        push    OFFSET c            ;@c
                    119:        push    1                   ;number of bytes to write
                    120:        push    ds
                    121:        push    OFFSET written      ;address to hold # bytes written
                    122:        call    FAR PTR DOSWRITE    ;synchronous write
                    123: 
                    124:        push    1                   ;write to standard output
                    125:        push    ds
                    126:        push    OFFSET const_1      ;addr of ".<cr><lf>"
                    127:        push    3                   ;number of bytes to write
                    128:        push    ds
                    129:        push    OFFSET written      ;address to hold # bytes written
                    130:        call    FAR PTR DOSWRITE    ;synchronous write
                    131: 
                    132:        mov     ax,1                ;indicates success
                    133:        pop     es                  ;restore registers
                    134:        pop     ds
                    135:        pop     si
                    136:        pop     di
                    137:        ret     
                    138: 
                    139: START  ENDP
                    140: ;---------------------------------------
                    141: ; PRINTDATA
                    142: ; Called by the attached process to display on the screen the current values
                    143: ; of the shared "count" and the non-shared "id".
                    144: 
                    145: 
                    146:        PUBLIC  PRINTDATA           ;entry point
                    147: PRINTDATA      PROC FAR
                    148: 
                    149:        push    di                  ;save registers
                    150:        push    si
                    151:        push    ds
                    152:        push    es
                    153: 
                    154:        mov     ax,SEG FRED         ;set up segment registers
                    155:        mov     ds,ax               ;ds points to global segment
                    156:        mov     ax,SEG ETHEL
                    157:        mov     es,ax               ;es points to non-shared segment
                    158: 
                    159:        push    1                   ;write to standard output
                    160:        push    ds
                    161:        push    OFFSET msg_beg      ;addr of "I am number "
                    162:        push    12                  ;number of bytes to write
                    163:        push    ds
                    164:        push    OFFSET written      ;address to hold # bytes written
                    165:        call    FAR PTR DOSWRITE    ;synchronous write
                    166: 
                    167:        mov     al,BYTE PTR es:id
                    168:        add     al,'0'              ;c = id + '0'
                    169:        mov     BYTE PTR c,al
                    170: 
                    171:        push    1                   ;write to standard output
                    172:        push    ds
                    173:        push    OFFSET c            ;@c
                    174:        push    1                   ;number of bytes to write
                    175:        push    ds
                    176:        push    OFFSET written      ;address to hold # bytes written
                    177:        call    FAR PTR DOSWRITE    ;synchronous write
                    178: 
                    179:        push    1                   ;write to standard output
                    180:        push    ds
                    181:        push    OFFSET msg_mid      ;addr of ".  There are "
                    182:        push    13                  ;number of bytes to write
                    183:        push    ds
                    184:        push    OFFSET written      ;address to hold # bytes written
                    185:        call    FAR PTR DOSWRITE    ;synchronous write
                    186: 
                    187:        mov     al,BYTE PTR count
                    188:        add     al,'0'              ;c = count + '0'
                    189:        mov     BYTE PTR c,al
                    190: 
                    191:        push    1                   ;write to standard output
                    192:        push    ds
                    193:        push    OFFSET c            ;@c
                    194:        push    1                   ;number of bytes to write
                    195:        push    ds
                    196:        push    OFFSET written      ;address to hold # bytes written
                    197:        call    FAR PTR DOSWRITE    ;synchronous write
                    198: 
                    199:        push    1                   ;write to standard output
                    200:        push    ds
                    201:        push    OFFSET msg_end      ;addr of " processes attached.<cr>"
                    202:        push    21                  ;number of bytes to write
                    203:        push    ds
                    204:        push    OFFSET written      ;address to hold # bytes written
                    205:        call    FAR PTR DOSWRITE    ;synchronous write
                    206: 
                    207:        pop     es                  ;restore registers
                    208:        pop     ds
                    209:        pop     si
                    210:        pop     di
                    211:        ret     
                    212: 
                    213: PRINTDATA      ENDP
                    214: ;---------------------------------------
                    215: _TEXT  ENDS
                    216: ;-----------------------------------------------------------------------------
                    217: END    START                       ;defines auto-initialization entry point

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.