Question: correct this coding: ORIG x 3 0 0 0 LD R 0 , INTRO _ PROMPT _ PTR ; Load address of intro prompt PUTS
correct this coding: ORIG x
LD R INTROPROMPTPTR ; Load address of intro prompt
PUTS ; Display intro prompt
LD R INPUTBUFFER ; Load address of input buffer
GETS ; Read input from user
AND R R # ; Clear R for accumulating sum
READLOOP
LDR R R # ; Load next input character
ADD R R # ; Increment buffer pointer
BRz PROCESSSUM ; Branch if end of string
LD R DIGITMASK ; Load mask to test if character is digit
AND R R R ; Test if character is digit
BRz READLOOP ; Branch if not digit
ADD R R # ; Convert ASCII digit to binary value
ADD R R R ; Add digit to sum
BR READLOOP ; Loop to read next character
PROCESSSUM
LD R OUTPUTBUFFER ; Load address of output buffer
LD R MAXDIGITVALUE ; Load max digit value
BRnp OUTPUTERROR ; Branch if sum is negative
ADD R R R ; Add to max digit value
BRn OUTPUTERROR ; Branch if sum overflows
STR R R # ; Store sum in output buffer
ADD R R # ; Increment buffer pointer
LEA R NEWLINE ; Load address of newline character
STR R R # ; Store newline in output buffer
PUTS ; Display output buffer
HALT ; End program
OUTPUTERROR
LD R ERRORMESSAGEPTR ; Load address of error message
PUTS ; Display error message
HALT ; End program
INTROPROMPTPTR FILL PROMPT ; Address of intro prompt string
ERRORMESSAGEPTR FILL ERRORMSG ; Address of error message string
INPUTBUFFER BLKW ; Input buffer with space for digits and null terminator
OUTPUTBUFFER BLKW ; Output buffer with space for digits, newline, and null terminator
DIGITMASK FILL xFF ; Mask to test if character is digit
MAXDIGITVALUE FILL # ; Maximum digit value for testing overflow
PROMPT STRINGZ "Enter a number:
ERRORMSG STRINGZ "Error: Input contains nondigit characters or sum overflows."
NEWLINE FILL xA ; Newline character
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
