The .contrl directive controls automatic code alteration by the assembler on instructions. This directive either decreases the number of bytes of the instruction (to optimize code), or increases the number of bytes of the jp, jmp and jsr instructions to avoid a range error. Note that in two-pass mode, the assembler can alter only those instructions which have their operand defined during pass 1, which excludes forward-reference operands. This is because the assembler must know the size of the instruction on pass 1. In optimize mode, the assembler can always choose the optimal size for these instructions.
The .contrl directive also allows maximum code size for all instructions to be selected for ease of patching code during debugging. The instructions all have maximum size operand fields, so any valid operand can be patched-in during debugging.
Control of the various options depends upon the three least-significant bits of the evaluated expression in the operand field (the expression must be defined during pass 1). Table 2-5 shows the options available, their associated bit weights and assembler default values. Table 2-6 shows the possible code alterations that may occur for the jump instructions.
The .contrl directive may be used throughout the program to enable or disable the alteration of code. Normally, it is desirable to disable code alteration of the instructions only during a block of code which must remain a fixed size (for example, a critical timing loop).
This directive takes precedence over any multi-pass optimization. Thus, if code reduction is disabled, no optimization will take place regardless of the number of passes.
.contrl 0 ; disable all code alteration . ; fixed size code block . . .contrl 3 ; re-enable code alteration
default | value (binary) | jp (1-byte) | jmp (2-byte) | jmpl (3-byte) | jsr (2-byte) | jsrl (3-byte) | description | effects |
---|---|---|---|---|---|---|---|---|
* | B'011 | jp or jmp or jmpl | jp or jmp or jmpl | jp or jmp or jmpl | jsr or jsrl | jsr or jsrl | jump range is increased if necessary and decreased if possible | this is the default |
B'001 | jp | jmp or jp | jmpl or jmp or jp | jsr | jsrl or jsr | jump range will not increase | errors are generated if jumps are out of range | |
B'010 | jp or jmp or jmpl | jmp or jmpl | jmpl | jsr or jsrl | jsr | jump range will not decrease | code size will not be optimized | |
B'000 | jp | jmp | jmpl | jsr | jsrl | assembly instructions are not changed | errors are generated if jumps are out of range and code size is not optimized | |
B'100, B'101, B'110 or B'111 | jmpl | jmpl | jmpl | jsrl | jsrl | largest jump range is used | code size is not optimal but useful when debug patching |
For further code optimization notes, see Chapter 4.
; default .CONTRL in effect ; (code alteration enabled) BACK: ; label ret ; note that following references to ; BACK are not forward-references jmp BACK ; reduced to single byte (jp) jp BACK ; no change (jp) ; note that following references to ; FORWORD are forward references ; assembler cannot alter these in two- ; pass mode but can in optimize mode jmp FORWORD ; no change (jmp) in two-pass, else (jp) jp FORWORD ; no change (jp) FORWORD: