Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Laboratory Exercise #10, you wrote an LC-3 program that rotated a given bit p

ID: 3905870 • Letter: I

Question

In Laboratory Exercise #10, you wrote an LC-3 program that rotated a given bit pattern (ORIGINAL) by a given amount (AMOUNT) and stored the result in ROTATED. In this programming activity, you will modify your program to prompt and retrieve the value of AMOUNT from the keyboard. Assume that the ORIGINAL is already in memory. Your program should then display the ORIGINAL and ROTATED bits as 16-character strings with correct labels.

Example: If ORIGINAL contains the bit pattern 1101000100001011 and the user entered a 5 as the amount to be rotated, then your program should display the following output:

AMOUNT: 5

ORIGINAL:    1101000100001011

ROTATED:     0010000101111010

Explanation / Answer

.ORIG x3000

GETC ;reads the ,character from keyboard and store it in R0

ADD R3,R0,x0 ;copy contents of R0 to R3

ADD R3,R3,#-16 ;converting the ascii into number

ADD R3,R3,#-16

ADD R3,R3,#-16

ADD R4,R5,x0 ;copy from R5 to R4

LOOP ADD R4,R4,R4 ;shifting is nothing but multilication by 2(one left shift)

ADD R3,R3,#-1 ;decrementing

BRP LOOP ;decrement untill the input value is zero

LEA R0,STRING

STRING .STRINGZ "AMOUNT:" ;display string

ADD R0,R5,x0

OUT

LEA R0,STRING

STRING .STRINGZ "ORIGINAL"

ADD R0,R3,x0

OUT

LEA R0,STRING

STRING .STRINGZ "ROTATED"

ADD R0,R3,x0

OUT

HALT

.END

NOTE: I have written the core logic for shifting according to the given input i assumed ORIGINAL is present in R5 you can also modify according to your wish

Thanks!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote