|
|
Microsoft OS/2 SDK 12-15-1987
; dynlib3.asm
;
; Created 17 August 1987 by Kevin Ruddell, Microsoft Corp
;
;
; Demonstrates the use of shared and non-shared data segments.
; When each process attaches, the contents of "count" (in a shared segment)
; is incremented and assigned to "id" (in a non-shared segment).
; "count" is used to detect the first time the initialization routine
; is invoked.
; When a process makes a call to PRINTDATA, the current values of
; "count" and "id" are displayed on the screen. They will be different for
; all but the last process to attach to the dll.
TITLE dynlib3
.286p
EXTRN DOSWRITE:FAR
;-----------------------------------------------------------------------------
;A fresh copy of this segment is created for each process attaching to the dll.
ETHEL SEGMENT WORD PUBLIC 'FAR_DATA'
id DW 00H ;unique to each attached process
ETHEL ENDS
;---------------------------------------
;This segment is shared by all processes attached to the dll.
FRED SEGMENT WORD PUBLIC 'FAR_DATA'
First DB 'First time initialization.', 0aH, 0dH, 00H
NotFirst DB 'Not first time initialization.', 0aH, 0dH, 00H
msg_beg DB 'I am number ', 00H
ORG $+1 ;to line up on word boundaries
const_1 DB '.', 0aH, 0dH, 00H
msg_mid DB '. There are ', 00H
count DW 00H ;number of processes which have attached
msg_end DB ' processes attached.', 0dH, 00H
written DW 00H ;bytes written
c DW 00H ;temporary variable
FRED ENDS
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
ASSUME CS: _TEXT, DS: FRED, ES: ETHEL
;---------------------------------------
_TEXT SEGMENT BYTE PUBLIC 'CODE'
;---------------------------------------
; START
; Initialization routine.
; Called for each process when the process attaches to the dll.
;
; count is initialized to 0 in its definition, and so can be used as a first-
; time switch. A First/NotFirst message is sent to the screen and count is
; incremented to reflect the number of processes which have attached to
; the dll. The freshly-incremented count is copied to the non-shared
; location id and is unique among the attached processes. Actually,
; accesses to count should be synchronized, but this is omitted for simplicity.
; The unique id is sent to the screen.
START PROC FAR
push di ;save registers
push si
push ds
push es
mov ax,SEG FRED ;set up segment registers
mov ds,ax ;ds points to global segment
mov ax,SEG ETHEL
mov es,ax ;es points to non-shared segment
mov ax,count
inc WORD PTR count ;bump shared count of attached processes
cmp ax,0 ;test for first time through
jne START_NOT
push 1 ;write to standard output (screen)
push ds
push OFFSET First ;address of "First time initialization."
push 28 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
jmp START_ID
START_NOT:
push 1 ;write to standard output
push ds
push OFFSET NotFirst ;addr of "Not first time initialization."
push 32 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
START_ID:
mov ax,count ;non-shared id = shared count
mov es:id,ax
push 1 ;write to standard output
push ds
push OFFSET msg_beg ;addr of "I am number "
push 12 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
mov al,BYTE PTR count
add al,'0' ;c = count + '0'
mov BYTE PTR c,al
push 1 ;write to standard output
push ds
push OFFSET c ;@c
push 1 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
push 1 ;write to standard output
push ds
push OFFSET const_1 ;addr of ".<cr><lf>"
push 3 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
mov ax,1 ;indicates success
pop es ;restore registers
pop ds
pop si
pop di
ret
START ENDP
;---------------------------------------
; PRINTDATA
; Called by the attached process to display on the screen the current values
; of the shared "count" and the non-shared "id".
PUBLIC PRINTDATA ;entry point
PRINTDATA PROC FAR
push di ;save registers
push si
push ds
push es
mov ax,SEG FRED ;set up segment registers
mov ds,ax ;ds points to global segment
mov ax,SEG ETHEL
mov es,ax ;es points to non-shared segment
push 1 ;write to standard output
push ds
push OFFSET msg_beg ;addr of "I am number "
push 12 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
mov al,BYTE PTR es:id
add al,'0' ;c = id + '0'
mov BYTE PTR c,al
push 1 ;write to standard output
push ds
push OFFSET c ;@c
push 1 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
push 1 ;write to standard output
push ds
push OFFSET msg_mid ;addr of ". There are "
push 13 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
mov al,BYTE PTR count
add al,'0' ;c = count + '0'
mov BYTE PTR c,al
push 1 ;write to standard output
push ds
push OFFSET c ;@c
push 1 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
push 1 ;write to standard output
push ds
push OFFSET msg_end ;addr of " processes attached.<cr>"
push 21 ;number of bytes to write
push ds
push OFFSET written ;address to hold # bytes written
call FAR PTR DOSWRITE ;synchronous write
pop es ;restore registers
pop ds
pop si
pop di
ret
PRINTDATA ENDP
;---------------------------------------
_TEXT ENDS
;-----------------------------------------------------------------------------
END START ;defines auto-initialization entry point
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.