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 x3000
DisplayPrompt:
LD R0, promptMessagePtr
PUTS
InitializeRegisters:
AND R4, R4, #0
AND R7, R7, #0
AND R2, R2, #0
LD R5, digitCounter
GetInitialChar:
GETC
OUT
LD R2, newlineValidator
ADD R2, R2, R0
BRz EndProgram
LD R2, plusValidator
ADD R2, R2, R0
BRz ReadDigits
LD R2, minusValidator
ADD R2, R2, R0
BRz ApplyNegativeFlag
BR DisplayErrorMessage
ApplyNegativeFlag:
ADD R7, R7, #-1
BRz ReadDigits
ReadDigits:
GETC
OUT
LD R2, newlineValidator
ADD R2, R2, R0
BRz EndProgram
LD R2, zeroValidator
ADD R2, R2, R0
BRn DisplayErrorMessage
LD R2, nineValidator
ADD R2, R2, R0
BRp DisplayErrorMessage
LD R2, zeroValidator ; ASCII TO DECIMAL
NOT R2, R2
ADD R2, R2, #1
ADD R0, R0, R2
LD R3, baseMultiplier
ADD R4, R4, R0 ; Add the current digit to the accumulated result
ADD R4, R4, R4 ; Multiply the accumulated result by 2
ADD R4, R4, R4 ; Multiply the accumulated result by 4
ADD R4, R4, R4 ; Multiply the accumulated result by 8
ADD R4, R4, R0 ; Add the current digit
ADD R5, R5, #-1
BRz EndProgram
BRp ReadDigits
DisplayErrorMessage:
LD R0, errorMessagePtr
PUTS
BR DisplayPrompt
EndProgram:
; IF FLAG IS SET TO NEGATIVE, CONVERT TO NEGATIVE
BRn ApplyNegativeSign
; OUTPUT NEWLINE
LD R0, newlineValidator
OUT
HALT
ApplyNegativeSign:
NOT R4, R4
ADD R4, R4, #1
BR EndProgram
; Program Data
promptMessagePtr .FILL xB000
errorMessagePtr .FILL xB200
; DATA
digitCounter .FILL #5
newlineValidator .FILL #-10
plusValidator .FILL #-43
minusValidator .FILL #-45
zeroValidator .FILL #-48
nineValidator .FILL #-57
baseMultiplier .FILL #10
.END
; Remote data
.ORIG xB000 ; prompt message
.STRINGZ "Input a positive or negative decimal number (max 5 digits), followed by ENTER
"
.END
.ORIG xB200 ; 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!