Constants - page 3 To handle full 32-bit constants, we're going to define a set of five registers: const, const8, const8-clearUpper, const8-setUpper, and const8-shiftFirst. All of these registers except "const" are RCL's only and share the same physical 32 flip-flops of the const register. The "const" register is the main register. It acts a completely standard 32-bit register. It requires no "flipping" or unusual activities. It has a standard RCL as described much earlier here. One can copy to it or from it and all 32-bits will copy, just as with all "normal" registers. The "const8" register however, is the modified register as just described. Note that it doesn't have "its own" bits, but stores directly into the bottom 8 bits of the const register. And it leaves the upper 24 bits of the const register untouched. const8-clearUpper is almost the same, but also clears (sets to all 0's) the upper 24 bits of the const register. const8-setUpper works likewise, but sets the upper 24 bits of const to all 1's. const8-shiftFirst shifts all 32 bits of the const register to the left by 8 bits before writing into the lowest 8 bits of the const register. Thus it takes 1 instruction to store an 8-bit constant into const, 2 instructions to store a 16-bit constant, 3 instructions to store a 24-bit constant, and 4 instructions to store a full 32-bit constant. To be complete and exact, here is how to store positive, negative, or unsigned constants of various sizes. Let "[X4:X3:X2:X1]" represent the 4 bytes of a data word, X4 being the most significant and X1 the least. Then to store: an 8-bit positive or unsigned constant: X1 => const8-clear an 8-bit negative constant: X1 => const8-set a 16-bit positive or unsigned constant: X2 => const8-clear ; X1 => const8-shift a 16-bit negative constant: X2 => const8-set ; X1 => const8-shift a 24-bit positive or unsigned constant: X3 => const8-clear ; X2,X1 => const8-shift a 24-bit negative constant: X3 => const8-set ; X2,X1 => const8-shift a 32-bit positive or unsigned constant: X4 => const8 ; X3,X2,X1 => const8-shift a 32-bit negative constant: X4 => const8 ; X3,X2,X1 => const8-shift In other words, put the highest order byte in first, clearing or setting the remainder of the const register as appropriate, and then shift in the remaining bytes. Finally, note that all of the above merely loads the const register. We still must do one more instruction to transfer it to where we want it. For example, to multiply by 10: 10 => const8-clear ; const => multiplier or to multiply by 521 (2*256 + 9) 2 => const8-clear ; 9 => const8-shift ; const => multiplier Our compiler handles all of the above transparently of course. One merely write: 521 => multiplier and the compiler would generate the rest.