A program that rotates a bit pattern to the left by a certainamount, (again a nu
ID: 3609709 • Letter: A
Question
A program that rotates a bit pattern to the left by a certainamount, (again a number between 0 and 16, including 0 and 16). Thebit pattern is found in location x3100 with the rotate amount inmemory location x3101. As before, the result is to be placed inlocation x3102. The program starts at location x3000. Thedifference between a rotate and a shift is that the bits that wouldhave been lost in the shift are 'wrapped' around and moved into theright side of the pattern. For example, if the original pattern is1101000100001011 and the rotate amount is 0000000000001100 (decimal12), the result in x3102 should be, 1011110100010000.
0011 0000 0000 0000 ST ???? ; program starts atlocation x3000
0010 001 100000000 LD,R1 ???? ; load bit patternto left rotate
0010 010 100000001 LD,R2 ???? ; load number of times torotate
0000 010 000001011 BRz DONE ; branch to done if countis 0
0101 011 011 1 00000 ADD R3,R3,#0 ; clearr3
0001 001 001 1 00000 ADD R1,R1,????; set condition code based onvalue in r1
0000 011 000000111 BRzp ???? ; branch if positive orzero
0001 011 011 1 00001 ADD R3,R3,#1; most significant bit is 1
0001 001 001 000 001 ADD R1,R1,#1; left shift byone
0001 001 001 000 011 ADD R1,R1,#3; add back in shifted outbit
0001 010 010 1 11111 ADD R2,R2,???? ; decrementcount
0000 111 000000010 BRnzp ???? ; branch to top ofloop
0011 001 100000010 ST R1, ???? ;store shiftedresult
1111 0000 00100101 TRAP x25; halt thesimulator
???? question marksindicate where I need help they are not part of the instruction,opcode, operands or any of the code itself.
Explanation / Answer
Dear, 0011 0000 0000 0000 .ORIG X3000 0010 001 100000000 LD,R1 105H ; load bit pattern to leftrotate0010 010 100000001 LD,R2 106H ; load number of times torotate
0000 010 000001011 BRz DONE ; branch to done if countis 0
0101 011 011 1 00000 ADD R3,R3,#0 ; clearr3
0001 001 001 1 00000 ADD R1,R1,#0; set condition code based onvalue in r1
0000 011 000000111 BRzp Not done ; branch ifpositive or zero
0001 011 011 1 00001 ADD R3,R3,#1; most significant bit is 1
0001 001 001 000 001 ADD R1,R1,#1; left shift byone
0001 001 001 000 011 ADD R1,R1,#3; add back in shifted outbit
0001 010 010 1 11111 ADD R2,R2,-1 ; decrementcount
0000 111 000000010 BRnzp loop ; branch to top ofloop
0011 001 100000010 ST R1, 3102 ;store shiftedresult
1111 0000 00100101 TRAP x25; halt thesimulator I hope this will helps you!!!!!!!!!!!!!1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.