Hardware Reference
In-Depth Information
chk_end
dec
lp_cnt
bne
again
; have we tested all 16 bits yet?
forever
bra
forever
end
Sometimes we need to shift a number larger than 16 bits. However, the HCS12 does not
have an instruction that does this. Suppose the number has k bytes and the most significant byte
is located at loc . The remaining k 2 1 bytes are located at loc 1 1, loc 1 2, . . . , loc 1 k 2 1, as
shown in Figure 2.16.
loc
loc + 1
loc + k - 1
...
msb
lsb
Figure 2.16 k bytes to be shifted
The logical shift-one-bit-to-the-right operation is shown in Figure 2.17.
loc
loc + 1
loc + k - 1
0
msb
lsb
Figure 2.17 Shift-one-bit-to-the-right operation
As shown in Figure 2.17,
Bit 7 of each byte will receive bit 0 of the byte on its immediate left with the
exception of the most significant byte, which will receive a 0.
Each byte will be shifted to the right by one bit. Bit 0 of the least significant byte
will be shifted out and lost.
The operation can therefore be implemented as follows:
Step 1
Shift the byte at loc to the right one place (using the lsr <opr> instruction).
Step 2
Rotate the byte at loc 1 1 to the right one place (using the ror <opr> instruction).
Step 3
Repeat step 2 for the remaining bytes.
By repeating this procedure, the given k -byte number can be shifted to the right as many bits as
desired. The operation to shift a multibyte number to the left should start from the least signifi -
cant byte and rotate the remaining bytes toward the most signifi cant byte.
Search WWH ::




Custom Search