dispatch.asm

来自「用汇编写的win32程序一些例子。」· 汇编 代码 · 共 82 行

ASM
82
字号
	.386
	.model flat

	PUBLIC	Dispatch, Translate

	.code
; **********************************************************************
;
; switch-case handler
;
Dispatch	PROC	
	push	ebx
	push	ecx
	mov	ebx,[esp+8]
	mov	ecx,dword ptr [ebx]
	add	ebx,4
dpl:
	cmp	eax,[ebx]
	jz	docall
	add	ebx,8
	loop	dpl
	mov	[esp+8],ebx
	pop	ecx
	pop	ebx
	stc
	ret
docall:
	pop	ecx
	push	offset finishup
	push	dword ptr [ebx+4]
	mov	ebx,[esp+8]
	ret
finishup:
	add	esp,4
	push	ebx
	push	eax
	mov	ebx,[esp+8]
	mov	eax,[ebx]
	lea	ebx,[ebx + 8 * eax + 4]	; Get offset to return address
	mov	[esp+8],ebx		; Xchg with orig value of ebx
	pop	eax
	pop	ebx
	ret
Dispatch	ENDP	
; ****************************************************************
;
; translate from one value to another
;
Translate	PROC	
	push	ebx
	push	ecx
	mov	ebx,[esp+8]
	mov	ecx,dword ptr [ebx]
	add	ebx,4
tpl:
	cmp	eax,[ebx]
	jz	doxlate
	add	ebx,8
	loop	tpl
	mov	[esp+8],ebx
	pop	ecx
	pop	ebx
	stc
	ret
doxlate:
	pop	ecx
	push	dword ptr [ebx + 4]
	mov	ebx,[esp+8]
	mov	eax,[ebx]
	lea	ebx,[ebx + 8 * eax + 4]	; Get offset to return address
	mov	[esp+8],ebx		; Xchg with orig value of ebx
	pop	eax
	pop	ebx
	ret
Translate	ENDP	
END
	
	
	
	
	
	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?