Answered step by step
Verified Expert Solution
Link Copied!

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 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
BRz GetDigits
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
Expected / Sample output
Output
Prompt
"Input a positive or negative decimal number (max 5 digits), followed by ENTER
"
Error Message
"ERROR! invalid input
"
Example
If the user enters +7246, your program should read the +,7,2,4,6 and end up with the value b0001110001001110(which is the two's complement representation of the number #7246, or x1C4E) in the specified register.
If the users enters -14237, your program should read the -,1,4,2,3,7 and end up with the value #-14237= xC863= b1100100001100011 in the specified register.
WARNING: In the following examples, the final result is shown in R5, 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 0/10!
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

Reflection on MBA marketing management class.

Answered: 1 week ago