Problem A
ARMPIT Computations
The popular ARMPIT processor has a simple architecture that
is built around a single register that is
Instruction |
Result |
ORWITH <v> |
modifies the register by performing a bitwise OR with <v> |
LSL <amt> |
bitwise left shifts the register by <amt> positions |
ROR <amt> |
bitwise right rotates the register by <amt> positions |
ADDONE |
increments the register by |
NOT |
inverts (complements) each bit in the register |
ADDSHIFT <amt> |
adds the register to a copy of itself that has been bitwise |
left shifted by <amt> positions |
In the above table:
-
<v> is an unsigned integer stored in
bits; bitwise OR combines this with the least significant bits of the register -
<amt> is an unsigned integer stored in
bits -
a left shift by <amt> positions moves <amt>
’s into the right end of the register, and discards the <amt> bits that “fall off” the left end -
a bitwise rotation by
position puts the least significant bit into the most significant bit position, and all other bits shift right by position; a bitwise rotation by <amt> positions is equivalent to <amt> successive rotate-by- operations -
for operations ADDONE and ADDSHIFT, addition is performed mod
, i.e., with truncation on overflow
Note that with the exception of ADDSHIFT, similar operations are found in most
CPU instruction sets. Here are examples of the supported
operations, assuming that the register stores
-
ORWITH makes the register
, since the OR of binary and is . -
LSL makes the register
, since left shifting by positions gives binary . If, on the other hand, the register initially stored , left shifting by positions would yield (binary ), because the result is truncated to bits. -
ROR makes the register
, since the binary value becomes when rotated rightward by positions. -
ADDONE makes the register store
. If the register had initially stored , it would contain after the ADDONE operation. -
NOT makes the register store
(binary ). -
ADDSHIFT makes the register store
, because is added to (see the example for LSL to explain the ).
For each of a given list of
Input
The first line of the input contains a positive integer,
Output
For each of the
Sample Input 1 | Sample Output 1 |
---|---|
4 769 0 10 20 |
3 0 1 2 |