Answered step by step
Verified Expert Solution
Link Copied!

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 x3000
; Output intro prompt
OutputPrompt:
LD R0, introPromptPtr
PUTS
; Set up flags, counters, accumulators as needed
SetRegisters:
AND R4, R4, #0
AND R7, R7, #0
AND R2, R2, #0
LD R5, counter
; Get first character, test for '
','+','-', digit/non-digit
GetFirstChar:
GETC
OUT
; Is the very first character ='
'? If so, just quit (no message)!
LD R2, newlineCheck
ADD R2, R2, R0
BRz QuitProg
; Is it ='+'? If so, ignore it, go get digits
LD R2, plusCheck
ADD R2, R2, R0
BRz GetDigits
; Is it ='-'? If so, set neg flag, go get digits
LD R2, minusCheck
ADD R2, R2, R0
BRz SetNegFlag
; Invalid initial character - output error message, start over
BR OutputErrorMessage
SetNegFlag:
ADD R7, R7, #-1
BRz GetDigits
GetDigits:
GETC
OUT
; IF NEWLINE, END PROG
LD R2, newlineCheck
ADD R2, R2, R0
BRz QuitProg
; Is it '0'? If so, it is not a digit - output error message, start over
LD R2, zeroCheck
ADD R2, R2, R0
BRn OutputErrorMessage
; Is it >'9'? If so, it is not a digit - output error message, start over
LD R2, nineCheck
ADD R2, R2, R0
BRp OutputErrorMessage
; If none of the above, the character is a numeric digit - convert it to number & store in target register!
LD R2, zeroCheck ; ASCII TO DECIMAL
NOT R2, R2
ADD R2, R2, #1
ADD R0, R0, R2
LD R3, multiplyFactor
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 QuitProg
BRp GetDigits
OutputErrorMessage:
LD R0, errorMessagePtr
PUTS
BR OutputPrompt
QuitProg:
; IF FLAG IS SET TO NEGATIVE, CONVERT TO NEGATIVE
BRn SetNegative
; OUTPUT NEWLINE
LD R0, newlineCheck
OUT
HALT
SetNegative:
NOT R4, R4
ADD R4, R4, #1
BR QuitProg
; Program Data
introPromptPtr .FILL xB000
errorMessagePtr .FILL xB200
; DATA
counter .FILL #5
newlineCheck .FILL #-10
plusCheck .FILL #-43
minusCheck .FILL #-45
zeroCheck .FILL #-48
nineCheck .FILL #-57
multiplyFactor .FILL #10
.END
; Remote data
.ORIG xB000 ; intro prompt
.STRINGZ "Input a positive or negative decimal number (max 5 digits), followed by ENTER
"
.END
.ORIG xB200 ; error message
.STRINGZ "ERROR: invalid input
"
.END
here are my errors:
Test + ve Number without Sign (0/15)
Test Failed: Failed: Program register output differs from the solution register outpu
est 5-digit +ve Number with Sign (0/15)
Test Failed: Failed: Program register output differs from the solution register outpu
Test -ve Number (015)
Test Failed: Failed: Program register output differs from the solution register outpu
Test 5-digit -ve Number (010)
Test Failed: Failed: Program register output differs from the solution register outpu
Test invalid initial character, +ve number w/sign (0/15)
Test Failed: Failed: Program register output differs from the solution register outpu
Test invalid internal character, -ve number (0/15)
Test Failed: Failed: Program register output differs from the solution register outpu
Test Double Sign, +ve number w/sign (0/10)
Test Failed: Failed: Program register output differs from the solution register outpu
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions