please use the pdf and the instruction provided below ;=================================================================================
;THE BINARY REPRESENTATION OF THE USER-ENTERED DECIMAL NUMBER MUST BE STORED IN R1
; output intro prompt
; Set up flags, counters, accumulators as needed
; Get first character, test for ‘n’, ‘+’, ‘-‘, digit/non-digit
; is very first character = ‘n’? if so, just quit (no message)!
; is it = ‘+’? if so, ignore it, go get digits
; is it = ‘-‘? if so, set neg flag, go get digits
; is it < '0'? if so, it is not a digit - o/p error message, start over ; is it > ‘9’? if so, it is not a digit – o/p error message, start over
; if none of the above, first character is first numeric digit – convert it to number & store in target register!
; Now get remaining digits from user in a loop (max 5), testing each to see if it is a digit, and build up number in accumulator
; remember to end with a newline!
; Program Data
; Remote data
.ORIG xB000; intro prompt
.STRINGZ “Input a positive or negative decimal number (max 5 digits), followed by ENTERn”
.ORIG xB200; error message
.STRINGZ “ERROR: invalid inputn”
; END of PROGRAM
; PURPOSE of PROGRAM
; Convert a sequence of up to 5 user-entered ascii numeric digits into a 16-bit two’s complement binary representation of the number.
; if the input sequence is less than 5 digits, it will be user-terminated with a newline (ENTER).
; Otherwise, the program will emit its own newline after 5 input digits.
; The program must end with a *single* newline, entered either by the user (< 5 digits), or by the program (5 digits)
; Input validation is performed on the individual characters as they are input, but not on the magnitude of the numbe
CS 61 - Programming Assignment 4
The purpose of this assignment is to illustrate how the .FILL pseudo-op performs the task of translating
textual decimal numbers (such as the string Ã¢â‚¬Å“+5392Ã¢â‚¬Â) into actual numbers (i.e. five thousand three
hundred and ninety two, represented of course as a 16-bit two's complement binary value).
High Level Description
Prompt the user to enter a signed multi-digit decimal number (max 5 digits) from the keyboard. Convert
the string of decimal numeric digits into the corresponding 16-bit two's complement number, stored in Ã¢â‚¬â€¹Rx
(i.e. one of the 8 registers: Ã¢â‚¬â€¹you will be told which register at the start of the provided starter codeÃ¢â‚¬â€¹).Ã¢â‚¬â€¹
The range of acceptable values is [-32768, +32767]; the absence of a sign means the number is positive i.e. the first character entered by the user may be '+', '-', or a numeric digit - and nothing else.
Your program can be broken down into the following tasks:
1. Ã¢â‚¬â€¹Read in the initial character.
Ã¢â€”Â If it is a Ã¢â‚¬Ëœ-Ã¢â‚¬Ëœ, make the final result negative by setting a "flag" Ã¢â‚¬â€¹(so if the "negative" flag is set, take the
2Ã¢â‚¬â„¢s complement of Ã¢â‚¬â€¹RxÃ¢â‚¬â€¹ at the end).
Ã¢â€”Â If it is '+' it can be ignored;
Ã¢â€”Â If it is a numeric digit, then the number is not negative, and the input is just the first numeric digit of
Ã¢â€”Â In all three cases, you can then proceed to accept any remaining digits Ã¢â‚¬â€¹(see item 2.)
Ã¢â€”Â If the initial character is a newline, the program can just terminate without any output.
Ã¢â€”Â Any other initial character must be treated as an error Ã¢â‚¬â€¹(see below)Ã¢â‚¬â€¹.
2. Ã¢â‚¬â€¹ConvertÃ¢â‚¬â€¹ the string of numeric digits input by the user into the binary number they represent Ã¢â‚¬â€¹(see
examples below)Ã¢â‚¬â€¹. To do this, you can follow this algorithm:
Ã¢â€”Â Initialize Rx (and any other registers as needed) to 0 - DO NOT do this by LD'ing 0 from memory!
There is a much simpler & faster way - remember the "TIP" in your lab 1 notes!
Ã¢â€”Â Convert each digit from ascii code to binary number as it is typed in, and add it to Rx;
as each subsequent digit is entered, multiply Rx by #10, and repeat
(go back to lab 1 & assn 1 to recall how to multiply!)
Stop when you detect the newline character ('n' = x0A), Ã¢â‚¬â€¹orÃ¢â‚¬â€¹ when you reach 5 input digits:
Ã¢â€”â€¹ For example, if the user types Ã¢â‚¬Ëœ2Ã¢â‚¬â„¢, then Rx will contain
#2 = b0000 0000 0000 0010
Ã¢â€”â€¹ If the user then types Ã¢â‚¬Ëœ3Ã¢â‚¬â„¢, making the string now read Ã¢â‚¬Å“23Ã¢â‚¬Â, then Rx will contain
2 x #10 + 3 = #23 = b0000 0000 0001 0111
Ã¢â€”â€¹ If the user then types Ã¢â‚¬Ëœ4Ã¢â‚¬â„¢, making the string read Ã¢â‚¬Å“234Ã¢â‚¬Â, then Rx will contain
#23 x #10 + 4 = #234 = b0000 0000 1110 1010
You must also perform Ã¢â‚¬â€¹input character validationÃ¢â‚¬â€¹ with this assignment Ã¢â‚¬â€œ i.e. reject any Ã¢â‚¬â€¹non-numericÃ¢â‚¬â€¹ input
character. That is, if the user enters Ã¢â‚¬Å“+23gÃ¢â‚¬Â, on detecting the non-numeric 'g', your program should output
an error, discard all input, and Ã¢â‚¬â€¹start over with the initial promptÃ¢â‚¬â€¹ Ã¢â‚¬â€¹(see sample output)Ã¢â‚¬â€¹.
You must also Ã¢â‚¬â€¹countÃ¢â‚¬â€¹ the number of characters entered - once it gets to 5 you should stop accepting new
characters, and issue a newline (in this case, Ã¢â‚¬â€¹do not waitÃ¢â‚¬â€¹ for the user to hit Enter).
However, you do not have to detect overflow in this assignment Ã¢â‚¬â€œ we will only test your code with inputs
in the range [-32768, +32767].
Expected / Sample output
Ã¢â€”â€¹ "Input a positive or negative decimal number (max 5 digits), followed by ENTERn"
Ã¢â€”Â Error Message
Ã¢â€”â€¹ "ERROR! invalid inputn"
If the user enters Ã¢â‚¬Å“+7246Ã¢â‚¬Â, your program should read the Ã¢â‚¬Ëœ+Ã¢â‚¬â„¢, Ã¢â‚¬Ëœ7Ã¢â‚¬â„¢, Ã¢â‚¬Ëœ2Ã¢â‚¬â„¢, Ã¢â‚¬Ëœ4Ã¢â‚¬â„¢, Ã¢â‚¬Ëœ6Ã¢â‚¬â„¢ and end up with the value
b0001 1100 0100 1110 Ã¢â‚¬â€¹(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 = b11001000 01100011 in Ã¢â‚¬â€¹the specified registerÃ¢â‚¬â€¹.
WARNING:Ã¢â‚¬â€¹ In the following examples, the final result is shown in R2, 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!
(Valid input with a negative sign)
(Valid input with a positive sign)
(Valid input with No sign)
(Invalid initial input, followed by valid input)
Ã¢â€”Â You must echo the digits as they are input (no "ghost writing").
Ã¢â€”Â You do Ã¢â‚¬â€¹notÃ¢â‚¬â€¹ have to output the converted binary number. It should simply be sitting happily in Ã¢â‚¬â€¹RxÃ¢â‚¬â€¹,
where you can check it in the simpl interface.
Remember, the register in which to store your result is given to you in your code header.
Ã¢â€”Â What should happen when an error occurs?
Ã¢â€”â€¹ Output "ERROR! invalid input" and start over, re-prompting the user for input
Ã¢â€”Â Possible errors Ã¢â‚¬â€¹(we will test for these!):Ã¢â‚¬â€¹
Ã¢â€”â€¹ Nothing entered before ENTER
(this does not trigger an error message, it just terminates the program)
Ã¢â€”â€¹ only a sign is entered, no numeric digits - Ã¢â‚¬â€¹error message, start over
Ã¢â€”â€¹ the first character entered is neither a sign nor a numeric digit - Ã¢â‚¬â€¹error message, start over
Ã¢â€”â€¹ A subsequent character is not a digit - Ã¢â‚¬â€¹error message, start over
- e.g. the sign character is entered twice, or a letter is entered in place of a digit
Ã¢â€”Â The entire program must end with a Ã¢â‚¬â€¹singleÃ¢â‚¬â€¹ newline.
EITHERÃ¢â‚¬â€¹ the user terminates digit entry with Enter ( < 5 digits), Ã¢â‚¬â€¹ORÃ¢â‚¬â€¹ the program issues its own newline
after counting 5 digits - not both!
Your code will obviously be tested with a range of different values: Make sure you do likewise!
Try writing this program out in C++/pseudocode before tackling it in LC3. Doing so often helps to simplify
the process and usually only takes a few minutes if you think it through carefully.
To "flag"a negative number, initialize a designated register (say Ry) to 0, then set it to, say, -1 if the first
character entered is a Ã¢â‚¬Ëœ-Ã¢â‚¬Ëœ.
Treat the subsequent numeric digits as a positive number. Once you have translated that number into
binary, test Ry and BÃ¢â‚¬â€¹ Rz MAKE_NEGATIVEÃ¢â‚¬â€¹ to take the 2Ã¢â‚¬â„¢s complement of the result if required.
Submit ("Upload") your Ã¢â‚¬â€¹assignment4.asmÃ¢â‚¬â€¹ file Ã¢â‚¬â€¹(and ONLY that file!)Ã¢â‚¬â€¹ to the Programming Assignment 4 folder in
Gradescope: the Autograder will run & report your grade within a minute or so.
You may submit as many times as you like - your grade will be that of your last submission.
If you wish to set your grade to a previous submission with a higher score, you may open your "Submission
history" and "Activate" any other submission - that's the one we will see.
Ã¢â€”Â To pass the assignment, you need a score of >= 80%.
The autograder will run several tests on your code, and assign a grade for each.
But certain errors Ã¢â‚¬â€¹(run-time errors, incorrect usage of I/O routines, missing newlines, etc.)Ã¢â‚¬â€¹ may cause
ALL tests to fail => 0/100! So submit early and study the autograder report carefully!!
Ã¢â€”Â You must use the template we provideÃ¢â‚¬â€¹ – if you make Ã¢â‚¬â€¹anyÃ¢â‚¬â€¹ changes to the provided starter code, the
autograder may not be able to interpret the output, resulting in a grade of 0.
Purchase answer to see full