-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paththread.asm
64 lines (53 loc) · 1.56 KB
/
thread.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
%include "io.inc"
extern _CreateThread@24
extern _WaitForSingleObject@8
COUNT equ 20
section .data
threadId1 dd 1
threadId2 dd 1
threadHandle1 dd 1
threadHandle2 dd 1
str1 db "Hello", 10, 0
str2 db "Aloha", 10, 0
section .text
global CMAIN
CMAIN:
push threadId1 ; the threadId will be placed there
push 0 ; run immediately
push 0 ; no parameter
push threadFun1 ; pointer to function
push 0 ; default stack size
push 0 ; default attributes
call _CreateThread@24
mov [threadHandle1], eax
push threadId2 ; the threadId will be placed there
push 0 ; run immediately
push 0 ; no parameter
push threadFun2 ; pointer to function
push 0 ; default stack size
push 0 ; default attributes
call _CreateThread@24
mov [threadHandle2], eax
push 0xffffffff ; wait indefinitely
push dword [threadHandle1]
call _WaitForSingleObject@8
push 0xffffffff ; wait indefinitely
push dword [threadHandle2]
call _WaitForSingleObject@8
retm
threadFun1:
mov ecx, COUNT
again1:
PRINT_STRING str1
dec ecx
jnz again1
mov eax, 0
retn
threadFun2:
mov ecx, COUNT
again2:
PRINT_STRING str2
dec ecx
jnz again2
mov eax, 0
retn