Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help my fix my code: . ORIG x 3 0 0 0 ; Output intro prompt OutputPrompt: LD R 0 , introPromptPtr PUTS ;
please help my fix my code:
ORIG x
; Output intro prompt
OutputPrompt:
LD R introPromptPtr
PUTS
; Set up flags, counters, accumulators as needed
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
BR GetFirstChar ; Jump back to the beginning
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
BRnp GetDigits
OutputErrorMessage:
LD R errorMessagePtr
PUTS
BR GetFirstChar ; Jump back to the beginning
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
Expected Sample output
Output
Prompt
"Input a positive or negative decimal number max digits followed by ENTER
Error Message
"ERROR! invalid input
Example
If the user enters your program should read the and end up with the value bwhich is the two's complement representation of the number # or xCE in the specified register.
If the users enters your program should read the and end up with the value # xC b in the specified register.
WARNING: In the following examples, the final result is shown in R which may NOT be the one you will use. You will store your result in the register specified in the header in your starter code!!
Make sure you get this right, or the grader will not work, and you will get
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