This file can be included to programs written in Euro Assembler.
The library contains OS-independent and width-independent macroinstructions
with calling convention similar to the standard Intel machine instruction set.
See also cpuext16.htm, cpuext32.htm, cpuext64.htm.
cpuext HEAD
Macro Dispatch implements the programming figure
switch. It compares value of the Control operand
(register or memory) with one or more Case values and, when equal, it jumps to
the corresponding label .Case: constructed from the compared value.
Macro does nothing when none of Case values was found equal to Control at run-time.
The label of target jump is constructed from the value by prefixing its verbatim notation with fullstop . and appending it with colon :, so it creates a local label. The label must exist somewhere in Dispatch's namespace, of course.
When the macro Dispatch is used several times in the same namespace, we can exploit different notations of the same number to avoid collision.Dispatch AL, 2
jumps to local label .2:, in other expansion of this macro we may dispatch to alternative labels which retain the value 2, such as2d, 2D, 0n2, 0x02, 0x00_02
.
Only letters and digits can be used in character constants, we cannot codeDispatch AL, '+', '-'
because.+:
and.-:
are invalid labels. UseDispatch AL, 0x2B, 0x2D
orDispatch AL, 43, 45
instead.
Dispatch %MACRO Control, Case1, Case2, , , %DispatchNr %SETA 2 ; Start with the second operand. %WHILE %DispatchNr <= %# ; Repeat with each Case* operand. > %DispatchArg %SET %*{%DispatchNr} ; Load the operand value to %DispatchArg. CMP %Control,%DispatchArg ; Emit instruction for the actual comparison. %IF "%DispatchArg[1]%DispatchArg[1]" === "''" ; Is the operand in apostrophes? JE .%DispatchArg[2..%&-1]: ; Strip them off and jump to this label. %ELSE JE .%DispatchArg: ; Use local label made from Case. %ENDIF %DispatchNr %SETA %DispatchNr+1 ; The next Case*. %ENDWHILE %ENDMACRO Dispatch
ENDHEAD