I’m implementing a 16-bit bit shifter to rotate bits to the left by r. I only have access to the AND, NOT and ADD operations. There are 3 condition codes: negative, zero and positive, which are set when you use any of these operations.
This is my approach:
ANDthe number with1000 0000 0000 0000to set condition codes to positive if the most significant bit is1.ADDthe number with itself. This shifts bits to the left by one.- If the MSB was
1,ADD1to the result. - Loop through steps (1)-(3) r times.
Are there any other efficient ways I can do this?
Since this is homework, I’ll help you think about it.
A left shift is a [some unknown] operation. That [some unknown] operation can be implemented using AND, NOT and ADD by doing…