Question: Write an LC-3 assembly language program to read in a two-digit decimal number whose digits add up to less than 10 and display the sum
Write an LC-3 assembly language program to read in a
two-digit decimal number whose digits add up to less than
10 and display the sum of those digits in the next line.
Sample execution
Please enter a two-digit decimal number > 27
The sum of the digits = 9
This is what I have so far. I'm probably approaching this wrong.
.ORIG x3000
LEA R0,PROMPT1 ; Displays first prompt.
PUTS
; First number
GETC ; Reads char
ST R0,CHAR ; Safe keeps char.
LD R0,CHAR ; Reload char
OUT ; Output a character to the monitor
; Second Number
GETC ; Reads char
ST R1,CHAR2 ; Safe keeps char.
LD R1,CHAR2 ; Reload char
OUT ; Output a character to the monitor
; Next Line
LD R0,CRLF ; Executes new line.
OUT ; Writes char
LEA R0,PROMPT2 ; Displays second prompt.
PUTS
LD R0,CRLF ; Executes new line.
OUT ; Writes char
LD R0,CHAR ; Reload first char
LD R1,CHAR ; Reload second char
LD R4,NEG30
ADD R0,R0,R1
ADD R0,R0,R4
OUT ; Displays uppercase.
HALT
;************ Data area*******************************
PROMPT1 .STRINGZ "Enter a two-digit decimal number> "
PROMPT2 .STRINGZ "The value of the two numbers added togeter> "
CHAR .BLKW 2
CHAR2 .BLKW 1
CHAR3 .BLKW 1
NEG30 .FILL #-48
CRLF .FILL #10
.END
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
