Answered step by step
Verified Expert Solution
Link Copied!

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 x3000
RESTART_PROGRAM
LD R0, introPromptPtr
PUTS ; Display the intro prompt
; Set up flags, counters, accumulators as needed - i hate this wording
AND R4, R4, #0 ; we clear r4 cause thats what we are using
AND R2, R2, #0 ; we use R2 for charagter input
AND R3, R3, #0 ; R3 for Ascii Comp
AND R5, R5, #0 ; R5 for flagging
AND R6, R6, #0 ; R6= temporary yse
GET_CHARACTER
GETC
OUT
ADD R2, R0, #0 ; Move character to R2
LD R3, ASCII_NEWLINE
ADD R2, R2, R3
BRz END_PROGRAM ; If first character is newline, quit without message
AND R2, R2, #0
LD R3, ASCII_PLUS
ADD R2, R0, #0
ADD R3, R3, R2
BRz SKIP_PLUS ; If first character is '+', ignore it
AND R2, R2, #0
LD R3, ASCII_MINUS
ADD R2, R0, #0
ADD R3, R3, R2
BRz SET_NEGATIVE_FLAG ; If first character is '-', set negative flag and continue onwards to hell
BR DIGIT_CHECK ; Otherwise, check if character is a digit. if not, then pray
DIGIT_CHECK
ADD R6, R6, #1 ; Increment character counter
; verify if less than 0 or greater than 9, cause thats digit boundaries
AND R2, R2, #0
ADD R2, R0, #0
LD R3, ASCII_NEWLINE
ADD R2, R2, R3
BRz PROCESS_NUMBER ;If newline, process the number
AND R2, R2, #0
LD R3, ASCII_ZERO
ADD R2, R0, #0
ADD R3, R3, R2
BRn ERROR ;If less than '0', output error
AND R2, R2, #0
LD R3, ASCII_NINE
ADD R2, R0, #0
ADD R3, R3, R2
BRp ERROR ; If character is greater than '9', output error
AND R2, R2, #0
ADD R2, R6, #-1
BRp INCREMENT_COUNTER ; If more than one character, increment counter
SET_NEGATIVE_FLAG
ADD R5, R5, #1
BR GET_NEXT_CHAR
SKIP_PLUS
GET_NEXT_CHAR
GETC
ADD R6, R6, #1
AND R2, R2, #0
ADD R2, R0, #0
LD R3, ASCII_NEWLINE
ADD R2, R2, R3
BRz PROCESS_NUMBER
OUT
AND R2, R2, #0
LD R3, ASCII_ZERO
ADD R2, R0, #0
ADD R3, R3, R2
BRn ERROR
AND R2, R2, #0
LD R3, ASCII_NINE
ADD R2, R0, #0
ADD R3, R3, R2
BRp ERROR
AND R2, R2, #0
ADD R2, R6, #-1
BRp INCREMENT_COUNTER
PROCESS_DIGIT
AND R2, R2, #0
LD R3, ASCII_ZERO
ADD R2, R0, #0
ADD R2, R2, R3
ADD R4, R4, R2
AND R5, R5, #0
ADD R5, R6, #-5
BRn GET_NEXT_CHAR
ADD R5, R5, #-1
BRz CONVERT_NEGATIVE
BR PROCESS_NUMBER
INCREMENT_COUNTER
AND R3, R3, #0
AND R2, R2, #0
ADD R2, R2, #9
ADD R3, R4, #0
LOOP_INCREMENT
ADD R4, R4, R3
ADD R2, R2, #-1
BRz PROCESS_DIGIT
BR LOOP_INCREMENT
ERROR
LEA R0, NEWLINE ; newline outpyt loaded and aimed
PUTS ; fired
LD R0, errorMessagePtr ; Load address of error message into barrel
PUTS ; fire!
BR RESTART_PROGRAM ; Restart program back to square one and pray user doest f* up the program
PROCESS_DIGIT2
AND R2, R2, #0
LD R3, ASCII_ZERO
ADD R2, R0, #0
ADD R2, R2, R3
ADD R4, R4, R2 ; Update result in R4 with new digit
AND R5, R5, #0
ADD R5, R6, #-5
BRn GET_NEXT_CHAR ; If less than 5 digits, get next character
BR PROCESS_NUMBER
CONVERT_NEGATIVE
NOT R4, R4 ; Convert R4 to two's complement
ADD R4, R4, #1
PROCESS_NUMBER
ADD R5, R5, #-1
BRz CONVERT_NEGATIVE ; If negative flag is set, convert to negative
LEA R0, NEWLINE
PUTS
END_PROGRAM
HALT
; Program Data
ASCII_MINUS .FILL #-45
ASCII_PLUS .FILL #-43
ASCII_ZERO .FILL #-48
ASCII_NINE .FILL #-57
ASCII_NEWLINE .FILL #-10
COUNT .FILL #5
NEWLINE .STRINGZ "
" ; Newline character
introPromptPtr .FILL xB000
errorMessagePtr .FILL xB200
.END
.ORIG xB000
.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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

=+a) Student ratings of an instructor on a 5 point Likert scale.

Answered: 1 week ago