User guide

158 CHAPTER 9. THE DESIGN OF CINTCODE
LG
LG1
LGH
b
h
B := A; A := G!(b+256)
B := A; A := G!b
B := A; A := G!h
b
Here, b and h are unsigned 8 and 16 bit values, resp e ct i vely.
9.1.2 Composite Instructions
Compactness can b e improved by combining commonly occurring pairs (and triples)
of operations into a single instructions. Many such composite instructions occur i n
Cintcode; for instance, AP3 adds local 3 to the A register, and L1P6 will load v!1 into
register A, assuming v is held in local 6.
9.1.3 Relative Addressing
A relative addressing mechanism is used in conditional and unconditional jumps and
the inst r uc ti on s: LL, LLL, SL and LF. All these instructions refer to locations within
the code and are opti m i se d for small relative distances. To simplify the codegenerator
all re l at i ve addressing instructions ar e 2 bytes in length. The first being the function
code and the second being an 8 bit r e l ati ve address.
Direct
Indirect
J a
J$ b hh
x
PC x
PC
dest = q + hh
dest = x + a
q = (x & #xFFFFFFFE) + 2*b
Figure 9.2: The relative addressing mechanism
All relative addressing instructions have two forms: direct and indirect, depending
on the least significant bit of the function byte. The details of both relative address
calculations are shown in figure 9.2, usi ng the instructions J and J$ as examples. For
the direct jump (J), the operand (a) is a signed byte in the range -128 to +127 which
is added to the address (x) of the operand byte to give the destination address (dest).
For the indirect jump, J$, the operand (b) is an unsigned byte in the range 0 to 255
which is doubl e d and added to the rounded version of x to gi ve the address (q) of a
16 bit signed value hh which is added to q to gi ve the destinati on address (dest).
The compiler places the resolving half word as late as possible to increase the chance
that it can be shared by other relative addressin g instructions to the same desination,
as coul d happen when several ENDCASE statements occur in a large SWITCHON