Tues, 8 Oct 2019, 00:57 more on rotating bits, since you need to understand this to do PL1.
My students, Some students have had a problem with the difference between shifting and rotating. Ergo, this email from me. What does it mean to "left rotate n bits"? Shifting seems to be easy, you just kick it out the left end of the register. For example, if the register contains 1111000011110000, left-shifting 3 bits means kicking out (i.e., throwing away) the three high-order bits (bits 15, 14, and 13), yielding 1000011110000, and then filling in the low-order bits (bits 2,1,0) with 0s. The result: 1000011110000000. Rotating is almost the same, EXCEPT instead of throwing away the high-order bits, we stick them back in at the low-order end. Again, if we started with 1111000011110000 and we threw away the 3 high order bits (111), rotating would mean putting them back in from the low-order end, giving us 1000011110000 after kicking out the three bits, and 1000011110000111 after reinserting them at the low order end. We can do this one bit at a time. In shifting, bit[15] gets thrown away, all the other bits move one bit to the left, and bit[0] gets replaced with a 0. In rotating, bit[15] still gets kicked out, all the other bits move one bit to the left, BUT bit[15] then gets put into bit[0]. So, for example, rotating by one bit the value 1111000011110000 produces 1110000111100001. The problem statement of the programming assingment talked about top n bits and bottom n bits. I like better: high-order (or most significant) bits and low-order (or least significant) bits. In the example shown in the PL1 writeup, we started with 1101000100001011, and rotated by 5 bits. That meant throwing away the 5 most significant bits (in this case 11010) and reinserting them in the least significant end, giving us 00100001011 after kicking out the 5 high order bits, and 0010000101111010 after reinserting 11010 from the least significant end. Hope the above helps show the difference between shifting to the left which sticks 0s in from the right end, and rotating which sticks the bits thrown out at the left back in at the right. I hope you get the program done by midnight Wednesday night. Good luck! Yale Patt