Question: what is wrong with my code: . ORIG x 3 0 0 0 DisplayPrompt: LD R 0 , promptMessagePtr PUTS InitializeRegisters: AND R 4 ,
what is wrong with my code: ORIG x
DisplayPrompt:
LD R promptMessagePtr
PUTS
InitializeRegisters:
AND R R #
AND R R #
AND R R #
LD R digitCounter
GetInitialChar:
GETC
OUT
LD R newlineValidator
ADD R R R
BRz EndProgram
LD R plusValidator
ADD R R R
BRz ReadDigits
LD R minusValidator
ADD R R R
BRz ApplyNegativeFlag
BR DisplayErrorMessage
ApplyNegativeFlag:
ADD R R #
BRz ReadDigits
ReadDigits:
GETC
OUT
LD R newlineValidator
ADD R R R
BRz EndProgram
LD R zeroValidator
ADD R R R
BRn DisplayErrorMessage
LD R nineValidator
ADD R R R
BRp DisplayErrorMessage
LD R zeroValidator ; ASCII TO DECIMAL
NOT R R
ADD R R #
ADD R R R
LD R baseMultiplier
ADD R R R ; Add the current digit to the accumulated result
ADD R R R ; Multiply the accumulated result by
ADD R R R ; Multiply the accumulated result by
ADD R R R ; Multiply the accumulated result by
ADD R R R ; Add the current digit
ADD R R #
BRz EndProgram
BRp ReadDigits
DisplayErrorMessage:
LD R errorMessagePtr
PUTS
BR DisplayPrompt
EndProgram:
; IF FLAG IS SET TO NEGATIVE, CONVERT TO NEGATIVE
BRn ApplyNegativeSign
; OUTPUT NEWLINE
LD R newlineValidator
OUT
HALT
ApplyNegativeSign:
NOT R R
ADD R R #
BR EndProgram
; Program Data
promptMessagePtr FILL xB
errorMessagePtr FILL xB
; DATA
digitCounter FILL #
newlineValidator FILL #
plusValidator FILL #
minusValidator FILL #
zeroValidator FILL #
nineValidator FILL #
baseMultiplier FILL #
END
; Remote data
ORIG xB ; prompt message
STRINGZ "Input a positive or negative decimal number max digits followed by ENTER
END
ORIG xB ; error message
STRINGZ "ERROR: invalid input
END
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
