circular shift is in fact necessary to put the correct digit into bit 0. Again, if the number 6 were originally represented in a register, as the register is shifted left three times its contents would be 12, 24, and 48 respectively. If a number is created during left shifting that exceeds the capacity of the register, this condition is indicated by setting an Arithmetic Overflow Flag\ArOvF. For l's or 2's complement notation, this condition is detected when a different bit is transferred into the sign position. That is, take the set of large 16-bit positive numbers which have bit positions 01~..~, where ~ indicates the bit may be either 0 or 1. This representation indicates numbers in the range 2^14 < n < 2^15 - 1. Shifting left would call for 2^15 < n < 2^16 - 1, which is impossible to represent in .a signed 16-bit register, which only has room for storing positive numbers up to 2^15 - 1. Large negative numbers can cause overflow in a similar way. Notice that for sign-magnitude representation, leaving the sign alone and shifting bits 14:0 left does not cause the sign to be lost when an overflow results, but the result is still erroneous. Under these conditions the result is:
result-number - original-number (x2) modulo 2^15
PROBLEM STATEMENT
Assume that a number to be shifted is held in the A register of a DMgpa. Design an RTM system (subprocess) to perform the three shift operations, logical, circular, and arithmetic (2's complement), for both the left (x2) and right (/2) cases as indicated in Figure SO-1. Assume that an arithmetic overflow will cause a 1 to be placed in the DMflag(Arithmetic-Overflow-Flag\ArOvF).
SOLUTION
The solution can be written down directly in terms of the data part statement as shown in Figure SO-1. The RTM diagram for the shift operations is given in Figure SO-2. In both the left and right shift cases the approach is to first establish the input bit, Shift-Flag\SF, to be shifted into A, and then carry out the appropriate shift operation. In the case of the arithmetic left shift (x2) the ArOvF (flag) may be set.
RELATED PROBLEM
The previous case only provided a single operation of x2 or /2. More generally, the number of shifts is also a parameter in the operation. That is, consider the three operations:(1)
A <- A x 2^N {arithmetic}
A <- A x 2^N {logical}
A <- A x 2^N (circular)
where N may be either positive, zero, or negative, giving a x2^N, null or /2^N operation. Design an RTM subprocess which takes A and N as input parameters and performs the appropriate operation for the logical shift case.
SOLUTION
Figure SO-3 shows the RTM diagram which solves the above problem. The parameter, N, to specify the number of shifts is held in a DMgpa when the macro
---------------------------
1. Hereafter arithmetic shifts will be assumed to be 2's complement, unless otherwise stated.
92