📄 testprcs.asm
字号:
.xlist
include stdlib.a
include process.a6
includelib stdlib.lib
option noscoped
.list
wp textequ <word ptr>
;*****************************************************************************
dseg segment para public 'data'
ofs equ <offset>
Child1 pcb <0,ofs endstk1, seg endstk1>
Child2 pcb <0,ofs endstk2, seg endstk2>
Child3 pcb <0,ofs endstk1, seg endstk1, ofs C3, seg C3>
Child4 pcb <0,ofs endstk2, seg endstk2, ofs C4, seg C4>
Parent pcb <>
ChildID1 dw 0
ChildID2 dw 0
ChildInc1 dw 0
ChildInc2 dw 0
ParentCntr dw 0
sema4 semaphore {}
dseg ends
;*****************************************************************************
cseg segment para public 'code'
assume cs:cseg, ds:dseg
;-----------------------------------------------------------------
Main proc
meminit
prcsinit
mov ax, dseg
mov ds, ax
lesi Child1
fork
cmp ax, 0
jne ThisIsChild1
mov ChildID1, bx ;Save child process ID
lesi Child2
fork
cmp ax, 0
jne ThisIsChild2
mov ChildID2, bx
;
;--------------------------------------------------------------------------
; This is the Parent:
;--------------------------------------------------------------------------
;
mov ParentCntr, 256
ParentLp: lesi sema4
WaitSemaph
printf
db "Parent: %d",cr,lf,0
dd ParentCntr
lesi sema4
RlsSemaph
dec ParentCntr
jne ParentLp
jmp QuitIt
;
;---------------------------------------------------------------------------
; This is child #1:
;---------------------------------------------------------------------------
;
ThisIsChild1: lesi sema4
WaitSemaph
printf
db "Child 1: %d",cr,lf,0
dd ChildInc1
lesi sema4
RlsSemaph
inc ChildInc1
jmp ThisIsChild1
;
;---------------------------------------------------------------------------
; This is child #2
;---------------------------------------------------------------------------
;
ThisIsChild2: sti
lesi sema4
WaitSemaph
printf
db "Child 2: %d",cr,lf,0
dd ChildInc2
lesi sema4
RlsSemaph
cli
inc ChildInc2
jmp ThisIsChild2
;---------------------------------------------------------------------------
QuitIt: prcsquit
;---------------------------------------------------------------------------
; Here's where the coroutine stuff starts.
;---------------------------------------------------------------------------
lesi Parent
coinit
print
db cr,lf,lf,"Coroutines:",cr,lf,0
mov bx, 10
CoLoop: print
db "Parent #2: ",0
mov ax, bx
puti
putcr
lesi Child3
cocall
cocall Child4
dec bx
jne CoLoop
jmp Quit
C3 proc
print
db "Child 3",cr,lf,0
cocall Parent
jmp C3
C3 endp
C4 proc
print
db "Child 4",cr,lf,0
cocall Parent
cocall Child3
jmp C4
C4 endp
Quit: ExitPgm ;DOS macro to quit program.
Main endp
cseg ends
; Allocate a reasonable amount of space for the stack (8k).
; Note: if you use the pattern matching package you should set up a
; somewhat larger stack.
sseg segment para stack 'stack'
stk1 db 256 dup ("stack ")
EndStk1 dw 0
stk2 db 256 dup ("stack ")
EndStk2 dw 0
stk db 256 dup ("stack ")
sseg ends
; zzzzzzseg must be the last segment that gets loaded into memory!
; This is where the heap begins.
zzzzzzseg segment para public 'zzzzzz'
LastBytes db 16 dup (?)
zzzzzzseg ends
end Main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -