이것은 오래된 게시물이지만 같은 문제가 발생하여 찾은 내용을 게시 할 것이라고 생각했습니다.
오른쪽으로 비트 시프트를해야 할 때 일반적으로 이진수를 2로 나누면 (2로 나누기) LC-3에서 문제가 될 수 있습니다. 이것은 내가 오른쪽으로 비트 이동을 수행하기 위해 작성한 코드입니다.
; Bit shift to the right
.ORIG x3000
MAIN
LD R3, VALUE
AND R5, R5, #0 ; Reseting our bit counter
B_RIGHT_LOOP
ADD R3, R3, #-2 ; Subtract 2 from the value stored in R3
BRn BR_END ; Exit the loop as soon as the number in R3 has gone negative
ADD R5, R5, #1 ; Add 1 to the bit counter
BR B_RIGHT_LOOP ; Start the loop over again
BR_END
ST R5, ANSWER ; Store the shifted value into the ANSWER variable
HALT ; Stop the program
; Variables
VALUE .FILL x3BBC ; Value is the number we want to do a bit-shift to the right
ANSWER .FILL x0000
.END
이 코드를 사용하면 가장 왼쪽 비트 B [0]이 손실됩니다. 또한 오른쪽으로 이동하려는 숫자가 음수이면이 코드가 작동하지 않습니다. 따라서 비트 [15]가 설정되면이 코드는 작동하지 않습니다. 예 :
VALUE .FILL x8000 ; binary value = 1000 0000 0000 0000
; and values higher than x8000
; won't work because their 15th
; bit is set
이 적어도 당신이 올바른 궤도에 가야한다.
여기를보세요. http://stackoverflow.com/questions/10077798/lc3-assembly-bitwise-right-shift – aggaton