Skip to content

Latest commit

 

History

History
29 lines (16 loc) · 1.77 KB

iii.3.66-switch.md

File metadata and controls

29 lines (16 loc) · 1.77 KB

III.3.66 switch – table switch based on value

Format Assembly Format Description
45 <unsigned int32> <int32><int32> switch ( t1, t2tN ) Jump to one of n values.

Stack Transition:

…, value → …,

Description:

The switch instruction implements a jump table. The format of the instruction is an unsigned int32 representing the number of targets N, followed by N int32 values specifying jump targets: these targets are represented as offsets (positive or negative) from the beginning of the instruction following this switch instruction.

The switch instruction pops value off the stack and compares it, as an unsigned integer, to n. If value is less than n, execution is transferred to the value'th target, where targets are numbered from 0 (i.e., a value of 0 takes the first target, a value of 1 takes the second target, and so on). If value is not less than n, execution continues at the next instruction (fall through).

If the target instruction has one or more prefix codes, control can only be transferred to the first of these prefixes. Control transfers into and out of try, catch, filter, and finally blocks cannot be performed by this instruction. (Such transfers are severely restricted and shall use the leave instruction instead; see Partition I for details).

Exceptions:

None.

Correctness:

Correct CIL obeys the control transfer constraints listed above.

Verifiability:

Verification requires the type-consistency of the stack, locals and arguments for every possible way of reaching all destination instructions. See §III.1.8 for more details.