Problem 4: (10 pts) write a LC-3 program. (a) For this problem, you will write a
ID: 3573308 • Letter: P
Question
Problem 4: (10 pts)
write a LC-3 program.
(a) For this problem, you will write a program that continuously takes single characters from the keyboard as input and outputs a character to the monitor depending on their case. It will use a subroutine called CheckCase? to perform this operation. You must implement a subroutine or you will not receive credit for your answer! ?Your program should do the following:
(1) From your main function, read an input character from the keyboard. If this character is equal to the ASCII value of "0", end the program. Otherwise, store this character into R2. (2) Call your CheckCase subroutine. This subroutine checks the value of your character to see if it it's uppercase, lowercase, or neither. (a) If it's uppercase, output "u" to the screen. (b) If it's lowercase, output "I" to the screen. (c) If it's a number or non-alphabetic character, output "n" to the screen. (3) Return back to your main function. You should continue taking and checking characters until the character 0 is found. Your program should have the following structure: Main FunctionExplanation / Answer
Your program is as follow :
.ORIG x3000 ; Start at x3000 above system memory
LD R1,NUMBER1 ; Load number 1 to R1
LD R3,NUMBER3 ; Load number 2 to R3
NOT R4 , R1 ; R4 = -R1
NOT R5 , R3 ; R5 = -R3
Main : LEA R0,INPROM
PUTS
GETC ; get a character from keyboard
LDI R2 , R2 , #0 ; Load 0 to R2
ADD R2,R2,R0 ; R2 = R2 + R0
JSR CheckCase ; Jump to CheckCase subroutine
STOP HALT ; Terminates the Program
CheckCase : ADD R2,R2,#0 ; add 0 to R2
BRz STOP ; Program terminted if R0 is 0.
LDI R6 , R6, R2 ; Store R2 to R6
ADD R6 , R6, R4 ; R6 = R6 - R4
BRp Num ; If Positive R6 < R4
LDI R7, R7, R2 ;Store R2 to R7
ADD R7, R7, R5 ; R7 = R7 - R5
BRp UPPER ; If Positive R7 < R5
LDI R2 , R2 , #l
OUT
RET
Num : LDI R6 , R6 , #n ; Load character n into R6
OUT
LDI R6 , R6, #0
BR Main
UPPER : LDI R7 , R7 , #u ; Load character n into R7
OUT
LDI R7 , R7, #0
BR Main
NUMBER1 .FILL #57 ;DECLARE NUMBER WE WANT TO COMPARE
NUMBER2 .FILL #90
Logic :
we are comparing two numnbers 57 and 90 respectively to check whether entered character is number,uppercase or lower case character.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.