Answered step by step
Verified Expert Solution
Question
1 Approved Answer
THis program runs, but During submission, I get the follwoing errors, related to positive and negative handling in registers. Please fix the program, perferably give
THis program runs, but During submission, I get the follwoing errors, related to positive and negative handling in registers. Please fix the program, perferably give me the whole thing to run, as well as individual parts. ty
ORIG x
RESTARTPROGRAM
LD R introPromptPtr
PUTS ; Display the intro prompt
; Set up flags, counters, accumulators as needed i hate this wording
AND R R # ; we clear r cause thats what we are using
AND R R # ; we use R for charagter input
AND R R # ; R for Ascii Comp
AND R R # ; R for flagging
AND R R # ; R temporary yse
GETCHARACTER
GETC
OUT
ADD R R # ; Move character to R
LD R ASCIINEWLINE
ADD R R R
BRz ENDPROGRAM ; If first character is newline, quit without message
AND R R #
LD R ASCIIPLUS
ADD R R #
ADD R R R
BRz SKIPPLUS ; If first character is ignore it
AND R R #
LD R ASCIIMINUS
ADD R R #
ADD R R R
BRz SETNEGATIVEFLAG ; If first character is set negative flag and continue onwards to hell
BR DIGITCHECK ; Otherwise, check if character is a digit. if not, then pray
DIGITCHECK
ADD R R # ; Increment character counter
; verify if less than or greater than cause thats digit boundaries
AND R R #
ADD R R #
LD R ASCIINEWLINE
ADD R R R
BRz PROCESSNUMBER ;If newline, process the number
AND R R #
LD R ASCIIZERO
ADD R R #
ADD R R R
BRn ERROR ;If less than output error
AND R R #
LD R ASCIININE
ADD R R #
ADD R R R
BRp ERROR ; If character is greater than output error
AND R R #
ADD R R #
BRp INCREMENTCOUNTER ; If more than one character, increment counter
SETNEGATIVEFLAG
ADD R R #
BR GETNEXTCHAR
SKIPPLUS
GETNEXTCHAR
GETC
ADD R R #
AND R R #
ADD R R #
LD R ASCIINEWLINE
ADD R R R
BRz PROCESSNUMBER
OUT
AND R R #
LD R ASCIIZERO
ADD R R #
ADD R R R
BRn ERROR
AND R R #
LD R ASCIININE
ADD R R #
ADD R R R
BRp ERROR
AND R R #
ADD R R #
BRp INCREMENTCOUNTER
PROCESSDIGIT
AND R R #
LD R ASCIIZERO
ADD R R #
ADD R R R
ADD R R R
AND R R #
ADD R R #
BRn GETNEXTCHAR
ADD R R #
BRz CONVERTNEGATIVE
BR PROCESSNUMBER
INCREMENTCOUNTER
AND R R #
AND R R #
ADD R R #
ADD R R #
LOOPINCREMENT
ADD R R R
ADD R R #
BRz PROCESSDIGIT
BR LOOPINCREMENT
ERROR
LEA R NEWLINE ; newline outpyt loaded and aimed
PUTS ; fired
LD R errorMessagePtr ; Load address of error message into barrel
PUTS ; fire!
BR RESTARTPROGRAM ; Restart program back to square one and pray user doest f up the program
PROCESSDIGIT
AND R R #
LD R ASCIIZERO
ADD R R #
ADD R R R
ADD R R R ; Update result in R with new digit
AND R R #
ADD R R #
BRn GETNEXTCHAR ; If less than digits, get next character
BR PROCESSNUMBER
CONVERTNEGATIVE
NOT R R ; Convert R to two's complement
ADD R R #
PROCESSNUMBER
ADD R R #
BRz CONVERTNEGATIVE ; If negative flag is set, convert to negative
LEA R NEWLINE
PUTS
ENDPROGRAM
HALT
; Program Data
ASCIIMINUS FILL #
ASCIIPLUS FILL #
ASCIIZERO FILL #
ASCIININE FILL #
ASCIINEWLINE FILL #
COUNT FILL #
NEWLINE STRINGZ
; Newline character
introPromptPtr FILL xB
errorMessagePtr FILL xB
END
ORIG xB
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
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