Metropoli BBS
VIEWER: lst9-6.asm MODE: TEXT (ASCII)
;
; *** Listing 9-6 ***
;
; An example of performing a switch statement with just a
; few cases, all consecutive, by using DEC to test for each
; of the cases.
;
; Macro to perform switch statement. This must be a macro
; rather than code inside the REPT block because MASM
; doesn't handle LOCAL declarations properly inside REPT
; blocks, but it does handle them properly inside macros.
;
HANDLE_SWITCH	macro
	local	ValueWas1, ValueWas2, ValueWas3, ValueWas4
	dec	cx
	jz	ValueWas1
	dec	cx
	jz	ValueWas2
	dec	cx
	jz	ValueWas3
	dec	cx
	jz	ValueWas4
;	<none of the above>
ValueWas1:
ValueWas2:
ValueWas3:
ValueWas4:
	endm
;
	call	ZTimerOn
TEST_VALUE = 1
	rept	1000
	mov	cx,TEST_VALUE	;set the test value
	HANDLE_SWITCH		;perform the switch test
TEST_VALUE = (TEST_VALUE MOD 5)+1 ;cycle the test value from
				; 0 to 3
	endm
	call	ZTimerOff

[ RETURN TO DIRECTORY ]