利用汇编实现表驱动
看Intel汇编语言程序设计的,感觉蛮有意思的
1 INCLUDE irvine32.inc
2
3 .data
4 CaseTable BYTE 'A'
5 DWORD PROCESS_A
6 EntrySize = ($ - CaseTable)
7 BYTE 'B'
8 DWORD PROCESS_B
9 BYTE 'C'
10 DWORD PROCESS_C
11 BYTE 'D'
12 DWORD PROCESS_D
13 NumberOfEntries = ($-CaseTable)/EntrySize
14 prompt BYTE "Press capital A,B,C,or D:",0
15
16 msgA BYTE "PROCESS_A",0
17 msgB BYTE "PROCESS_B",0
18 msgC BYTE "PROCESS_C",0
19 msgD BYTE "PROCESS_D",0
20
21 .code
22
23 main PROC
24 mov edx,OFFSET prompt
25 call WriteString
26 call ReadChar
27 mov ebx,OFFSET CaseTable
28 mov ecx,NumberOfEntries
29 L1:
30 cmp al,[ebx]
31 jne L2
32 call NEAR PTR [ebx+1]
33 call WriteString
34 call Crlf
35 jmp L3
36 L2:
37 add ebx,EntrySize
38 loop L1
39
40 L3:
41 ret
42 main endp
43
44 PROCESS_A PROC
45
46 mov edx,OFFSET msgA
47 ret
48
49 PROCESS_A endp
50
51 PROCESS_B PROC
52
53 mov edx,OFFSET msgB
54 ret
55
56 PROCESS_B endp
57
58 PROCESS_C PROC
59
60 mov edx,OFFSET msgC
61 ret
62
63 PROCESS_C endp
64
65 PROCESS_D PROC
66
67 mov edx,OFFSET msgD
68 ret
69
70 PROCESS_D endp
71
72 Debug PROC
73
74 pushad
75 mov edx,OFFSET Debug
76 call WriteString
77 popad
78 ret
79
80 Debug endp
81
82 END main