There’s two distinct approaches you can take when coding shifts and rotate instructions:
1) Hardcoded Shift Factor – Here’s a typical shift and round packed instruction –
The 3 is a shift factor that represents a 3 digit left shift. It has the advantage of being easy to code, but the shift factor is fixed and can’t be programmatically altered.
2) Computed Shift Factor – This second technique is less commonly coded, so perhaps you haven’t seen an SRP coded like this:
Just how does this second SRP above work? First the shift factor is loaded into register 4. The 0(R4) is in fact a base/displacement address. Like all base/displacement computations, the contents of the base register and the displacement are added to produce an effective address. But instead of using the effective address to reference a memory location, only the rightmost six bits of the address are used as a shift factor. In the case of SRP, the 6 bits are interpreted as a 2’s complement binary integer, and the shift moves left for positive integers and right for negative ones. An advantage to this technique is the shift factor can be programmatically changed, providing a flexibility that the first approach doesn’t offer.
In both cases, the shift factor is expressed as a base/displacement address. In the first case the 3 is simply a displacement and the base register was omitted, so it defaulted to 0. The effective address was the displacement, 3. Abreviating this to six bits, left 3 as the shift factor.
There are lots of opportunities to use these techniques because there are many shift and rotate instructions (including SRP) that express their shift factors in base displacement format D(B).
These instructions include:
For each of these instructions, the base/displacement address in not used as an address at all. In fact, only the last 6 bits of the “address” is used to represent the shift factor. Some shift factors are in plain binary while others are in 2’s complement. You’ll have to check with the Principles of Operation for the details on each instruction.