Question: LC-3 Assembly Language Coding: Read in the + or -. If the character is a -, remember to make the final result negative (i.e. take
LC-3 Assembly Language Coding:
Read in the + or -. If the character is a -, remember to make the final result negative (i.e. take
the 2s co mplement of R5 at the end). If the result is positive then ... dont. Convert the string of characters input by the user into the binary number they represent (see
examples). To do this, you can follow this algorithm:
Initiali ze R5 to 0 (DO NOT do this by LD'ing a 0 from memory! There is a much simpler & faster way!)
Convert each digit to binary as it is typed in, and add it to R5 ; if another digit is entered, multiply R5 by 10, and repeat. Stop when you detect the ENTER (x0A):
For example, if the user types 2, then R5 will contain #2 == b0000 0000 0000 0010
If the user then types a 3, making the string now read 23, then R5 will contain 2 x 10 + 3 == #23 == b0000 0000 0001 0111
If the user then types 4, making the string read 234, then R5 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, your program should "choke" on the g, print an error message (see sample output), and start over at the beginning with the initial prompt.
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
Output
Prompt Input a positive or negative decimal number (max 5 digits), followed by ENTER
Newline terminated Error Message
ERROR INVALID INPUT Newline terminated
Example
If the user enters +7246, your program should read the +, 7, 2, 4, 6 and end up with the value b0001 1100 0100 1110 in R5 (which corresponds to the number #7246, or x1C4E).
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 R5 .
NOTE: In the following examples, the final result is shown in R2. This is NOT the register you will be using in your code - use the register specified above!!




Note:
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
R5 , where you can check it in simpl.
What should happen when an error occurs?
Output "ERROR INVALID INPUT" and start over, prompting the user for input
Other Errors (output "ERROR INVALID INPUT" and start over):
Nothing entered before ENTER
only sign is entered before ENTER
first character entered is neither a sign nor a digit
REMEMBER: all outputs must be newline terminated
LC-3 Console Output from the machine will appear here. In the box below you can specify input. Enter text beforehand, or type while the program is running. Specify bulk input by pasting Input a positive or negative decimal number (max 5 digits), followed by ENTER -7125 RO00A 10 R4xFFF6 110 |10 (Valid input with a negative sign) 7125 R3 0004 4 1-1 RII0000 10 |RS|0000 REIFFFF RZ x3049 MAX_INPUT LC-3 Console Output from the machine will appear here. In the box below you can specify input. Enter text beforehand, or type while the program is running. Specify bulk input by pasting Input a positive or negative decimal number (max 5 digits), followed by ENTER -7125 RO00A 10 R4xFFF6 110 |10 (Valid input with a negative sign) 7125 R3 0004 4 1-1 RII0000 10 |RS|0000 REIFFFF RZ x3049 MAX_INPUT
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
