Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can you fix my code I have errors: code: . ORIG x 3 0 0 0 ; Output intro prompt OutputPrompt: LD R 0 ,
can you fix my code I have errors:
code:
ORIG x
; Output intro prompt
OutputPrompt:
LD R introPromptPtr
PUTS
; Set up flags, counters, accumulators as needed
SetRegisters:
AND R R #
AND R R #
AND R R #
LD R counter
; Get first character, test for
digitnondigit
GetFirstChar:
GETC
OUT
; Is the very first character
If so just quit no message
LD R newlineCheck
ADD R R R
BRz QuitProg
; Is it If so ignore it go get digits
LD R plusCheck
ADD R R R
BRz GetDigits
; Is it If so set neg flag, go get digits
LD R minusCheck
ADD R R R
BRz SetNegFlag
; Invalid initial character output error message, start over
BR OutputErrorMessage
SetNegFlag:
ADD R R #
BRz GetDigits
GetDigits:
GETC
OUT
; IF NEWLINE, END PROG
LD R newlineCheck
ADD R R R
BRz QuitProg
; Is it If so it is not a digit output error message, start over
LD R zeroCheck
ADD R R R
BRn OutputErrorMessage
; Is it If so it is not a digit output error message, start over
LD R nineCheck
ADD R R R
BRp OutputErrorMessage
; If none of the above, the character is a numeric digit convert it to number & store in target register!
LD R zeroCheck ; ASCII TO DECIMAL
NOT R R
ADD R R #
ADD R R R
LD R multiplyFactor
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 QuitProg
BRp GetDigits
OutputErrorMessage:
LD R errorMessagePtr
PUTS
BR OutputPrompt
QuitProg:
; IF FLAG IS SET TO NEGATIVE, CONVERT TO NEGATIVE
BRn SetNegative
; OUTPUT NEWLINE
LD R newlineCheck
OUT
HALT
SetNegative:
NOT R R
ADD R R #
BR QuitProg
; Program Data
introPromptPtr FILL xB
errorMessagePtr FILL xB
; DATA
counter FILL #
newlineCheck FILL #
plusCheck FILL #
minusCheck FILL #
zeroCheck FILL #
nineCheck FILL #
multiplyFactor FILL #
END
; Remote data
ORIG xB ; intro prompt
STRINGZ "Input a positive or negative decimal number max digits followed by ENTER
END
ORIG xB ; error message
STRINGZ "ERROR: invalid input
END
here are my errors:
Test ve Number without Sign
Test Failed: Failed: Program register output differs from the solution register outpu
est digit ve Number with Sign
Test Failed: Failed: Program register output differs from the solution register outpu
Test ve Number
Test Failed: Failed: Program register output differs from the solution register outpu
Test digit ve Number
Test Failed: Failed: Program register output differs from the solution register outpu
Test invalid initial character, ve number wsign
Test Failed: Failed: Program register output differs from the solution register outpu
Test invalid internal character, ve number
Test Failed: Failed: Program register output differs from the solution register outpu
Test Double Sign, ve number wsign
Test Failed: Failed: Program register output differs from the solution register outpu
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started