I am doing a project that follows as:
You will edit the program you wrote for Lab #9 that prompts the user for the value of the number of bits to rotate (AMOUNT) a given value (ORIGINAL), and stores the rotated (ROTATED) value.
For this lab exercise, you will need to display on the console, the values of ORIGINAL and ROTATED bits as 16-character strings with correct labels.
Example: If ORIGINAL contains the bit pattern 1111000000001111 and the user entered a 5 as the amount to be rotated, then your program should display the following output:
AMOUNT: 5
ORIGINAL: 1111000000001111
ROTATED: 0000000111111110
MY code is as follows:
.ORIG x3000
LEA R0 PROMPT ; loads R0 with the starting address of prompt
PUTS ; prints prompt
LD R0 ENDLINE
OUT
GETC
OUT
ADD R4 R0 #0
ADD R4 R4 #-16
ADD R4 R4 #-16
ADD R4 R4 #-16
GETC
OUT
ADD R5 R0 #0
ADD R5 R5 #0
ADD R5 R5 #-16
ADD R5 R5 #-16
ADD R5 R5 #-16
ADD R4 R4 #0
BRz zloop
ADD R5 R5 #10
zloop
ST R5 AMOUNT
ST R6 AMOUNT
LD R2, MASK ; MASK = 1000 0000 0000 0000 for checking MSB
LD R0, ORIGINAL ; ORIGINAL = xF00F
loop2
AND R3, R2, R0 ; checks to see if MSB is 0 or 1(negative)
BRn loop ; ignores next code if negative (i.e. MSB = 1)
ADD R0, R0, R0 ; Left Shift
ADD R5, R5, #-1 ; AMOUNT--
ADD R6, R6 #1
BRp loop2 ; if still positive, repeat check from above
BRz loop3 ; if negative, we're done! so jumps to store final ORIGINAL value
loop ; comes here after checking if MSB is 1
ADD R0, R0, R0 ; left shift
ADD R0, R0, #1 ; add 1 to rotate
ADD R5, R5, #-1 ; decrement amount
ADD R6, R6 #1
BRp loop2 ; if positive, we still have work to do. jumps up to loop2 to go through check again
loop3 ; we will arrive here if ORIGINAL value is positive and AMOUNT is 0
LD R0 ENDLINE
OUT
LEA R0, AMOUNTSTR
PUTS
ADD R0 R6 #0
HALT
OUT
LD R0 ENDLINE
ST R0, ROTATED ; stores original into ROTATED
ENDLINE .FILL x000A
AMOUNT .FILL x001E
ROTATED .BLKW #1
ORIGINAL .FILL xF00F
ORIGSTR .STRINGZ "ORIGINAL: 1111000000001111"
AMOUNTSTR .STRINGZ "AMOUNT: "
MASK .FILL x8000
PROMPT .STRINGZ "Enter a two digit number to rotate a binary string up to 16 bits. Example: 05"
.END
When I run it and enter in the digits, I either get a square with a question mark in it or a an ASCII code that is not what I need. I tried to see if I had to add the corresponding ASCII value difference to get the character I was looking for, and that's when I kept getting the blocked question mark.
Any help would be appreciated!