条件处理与有限状态机编程
1. 表驱动选择方法
表驱动选择方法虽然在初始阶段会有一些开销,但它能减少代码编写量。通过一个表可以处理大量的比较操作,并且相较于一系列的比较、跳转和调用指令,表更容易修改,甚至可以在运行时重新配置。
以下是一个示例代码:
main PROC
mov edx,OFFSET prompt
; ask user for input
call Writestring
call ReadChar
; read character into AL
mov ebx,OFFSET CaseTable
; point EBX to the table
mov ecx,NumberOfEntries
; loop counter
Li:
cmp al, [ebx]
; match found?
jne L2
; no: continue
call NEAR PTR [ebx + 1]
; yes: call the procedure
call Writestring
; display message
call Crlf
jmp L3
; exit the search
L2:
add ebx,EntrySize
; point to the next entry
loop Li
; repeat until ECX = 0
L3:
exit
main ENDP
Process_A PROC
mov edx,
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



