Programming Part:
Question 1 [15 marks)
Your task is to write a program that permutes the bits of the 16-bit data item stored in the
memory location Data. How the bits will be permuted is defined by memory location
WriteStep. Starting with the least significant bit of Data, copy that bit value WriteStep bits
from the least significant bit (moving left from the least significant bit) of your result. Now.
reading from Data, move one bit to the left and copy that bit another WriteStep bits from
where you last wrote a bit in your result, being sure to cycle back to the beginning of the
word as required. Repeat until all 16 bits have been copied. See below for a visual example
where WriteStep == 7. Test your program with the following values stored in Data and
WriteStep (respectively):
a. x0001, 3 (the correct number of rounds, see below, is 8)
d. XA5A5, 3
• XBEEF. 11
f. ×BEEF, 7
Continue to perform this permuting operation on the resulting word until your result returns
to the value in Data. Print the number of such permutation rounds required to return to the
original value.
1. If you start with a result of all zero bits you will only need to copy over the one bits. To
copy is to make sure the correct bit is set in the result word
2. You will need to make use of (portions) of both assignment 1 programming solutions.
3. To read and write bits you will need a bit mask, which you can shift as you are
stepping through the words. To shift a bit one location to the left is to multiply the
value by 2. You don’t need to implement multiplication to do a “multiplication by 2”.
4. You can assume that all permutations will require less than 10 rounds. As such, you
can use one of the ASCII tricks to convert the number into its ASCII value for printing.