Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you fix my code to have the expected outputs, it assemble but does not have the correct outputs or it doesnt work, if possible

can you fix my code to have the expected outputs, it assemble but does not have the correct outputs or it doesnt work, if possible please show me the full corrected code, thank you!
.ORIG x3000
; Output intro prompt
OutputPrompt:
LD R0, introPromptPtr
PUTS
; Set up flags, counters, accumulators as needed
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
BR GetFirstChar ; Jump back to the beginning
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
BRnp GetDigits
OutputErrorMessage:
LD R0, errorMessagePtr
PUTS
BR GetFirstChar ; Jump back to the beginning
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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

What is the purpose of the staffing practice called Two-in-aBox?

Answered: 1 week ago

Question

What would you do?

Answered: 1 week ago