have this code but it needs to work in lc3 stimulate by, it only allows user to type characters and does not prompt user with instructions etc. Prompt the user with instructions Allow user to type characters They will be uppercase, lowercase, numbers, spaces, and punctuation Show the user each character they typed as they type them When the user types numeric zero (0), stop accepting character Report to user how many lowercase 'a's were entered to the user Automatically start over .ORIG x3000 AND R1,R1,#0 ; R1=0 (counter) LD R3, ASCIIA ; R3=#97 NOT R3,R3 ADD R3,R3,#1 ; R3=#-97 LD R4, ASCII0 ; R4=#48 NOT R4,R4 ADD R4,R4,#1 ; R4=#-48 loop GETC ; Read a characters from keyboard. OUT ; print the character entered ADD R2,R0,R4 ; check whether character is 0 BRZ done ; if character is 0, exit the loop ADD R2,R0,R3 ; otherwise, check whether the character is 'a' BRZ count ; if character is 'a', go to label Count BR loop ; otherwise, repeat the loop count ADD R1,R1,#1 ; increment the counter by 1 BR loop ; repeat the loop done LD R0,ASCNEL ; R0=#10 OUT ; print new line LD R4, ASCII0 ; R4=#48 AND R0,R0,#0 ; R0=#0 ADD R0,R4,R1 ; R0=R4+R1 (convert the counter to ascii digit) OUT ; print the counter(as ascii digit) HALT ASCII0 .FILL x0030 ;#48 ASCII of '0' ASCIIA .FILL x0061 ;#97 ASCII of 'a' ASCNEL .FILL x000A ;#10 ASCII of '\n' .END
I have this code but it needs to work in lc3 stimulate by, it only allows user to type characters and does not prompt user with instructions etc.
- Prompt the user with instructions
- Allow user to type characters
- They will be uppercase, lowercase, numbers, spaces, and punctuation
- Show the user each character they typed as they type them
- When the user types numeric zero (0), stop accepting character
- Report to user how many lowercase 'a's were entered to the user
- Automatically start over
.ORIG x3000
AND R1,R1,#0 ; R1=0 (counter)
LD R3, ASCIIA ; R3=#97
NOT R3,R3
ADD R3,R3,#1 ; R3=#-97
LD R4, ASCII0 ; R4=#48
NOT R4,R4
ADD R4,R4,#1 ; R4=#-48
loop GETC ; Read a characters from keyboard.
OUT ; print the character entered
ADD R2,R0,R4 ; check whether character is 0
BRZ done ; if character is 0, exit the loop
ADD R2,R0,R3 ; otherwise, check whether the character is 'a'
BRZ count ; if character is 'a', go to label Count
BR loop ; otherwise, repeat the loop
count
ADD R1,R1,#1 ; increment the counter by 1
BR loop ; repeat the loop
done LD R0,ASCNEL ; R0=#10
OUT ; print new line
LD R4, ASCII0 ; R4=#48
AND R0,R0,#0 ; R0=#0
ADD R0,R4,R1 ; R0=R4+R1 (convert the counter to ascii digit)
OUT ; print the counter(as ascii digit)
HALT
ASCII0 .FILL x0030 ;#48 ASCII of '0'
ASCIIA .FILL x0061 ;#97 ASCII of 'a'
ASCNEL .FILL x000A ;#10 ASCII of '\n'
.END
Step by step
Solved in 3 steps