Question
In LC-3 assembly language: Objective The purpose of this assignment is to illustrate how the .FILL pseudo-op performs the task of translating textual numbers (such
In LC-3 assembly language:
Objective The purpose of this assignment is to illustrate how the .FILL pseudo-op performs the task of translating textual 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 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 on the first line 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. Your Tasks Your program can be broken down into the following tasks: Read in the initial character. If it is a -, remember to make the final result negative by setting a "flag" (i.e. if the "negative" flag is set, take the 2s complement of Rx at the end). If the initial character is '+' or a numeric digit, then the number entered is not negative. Any other initial character must be treated as an error (see below) Convert the string of characters 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 a 0 from memory! There is a much simpler & faster way!) Convert each digit from ascii code to binary number as it is typed in, and add it to Rx; as subsequent digits are entered, multiply Rx by #10, and repeat. Stop when you detect the newline character (x0A): 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, 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 (i.e. in this case, do not wait for the user's newline). 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 (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 is NOT what you will use. You will store your result instead in the register specified at the bottom of 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)
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 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, prompting the user for input Possible errors (we will test for these!): Nothing entered before ENTER only sign is entered, no numeric digits first character entered is neither a sign nor a numeric digit Any subsequent character is not a digit - e.g. the sign character is entered twice, or a letter is entered in place of a digit
REMEMBER: all outputs must be newline terminated
-This is the starter code given with the assignment
;=================================================================================
;THE BINARY REPRESENTATION OF THE USER-ENTERED DECIMAL NUMBER MUST BE STORED IN R4
;=================================================================================
.ORIG x3000 ; Program begins here
;-------------
;Instructions
;-------------
;-------------------------------
;INSERT CODE STARTING FROM HERE
;--------------------------------
;Example of how to Output Intro Message
;LD R0, introMessagePtr ; Get pointer to Intro Message
;PUTS
;Example of how to Output Error Message
;LD R0, errorMessagePtr ; Get pointer to Error Message
;PUTS
;---------------
;Data
;---------------
introMessagePtr .FILL x6000
errorMessagePtr .FILL x6100
;------------
;Remote data
;------------
.ORIG x6000
;---------------
;messages
;---------------
intro .STRINGZ "Input a positive or negative decimal number (max 5 digits), followed by ENTER "
;---------------
;error_messages
;---------------
.ORIG x6100
error_msg1 .STRINGZ "ERROR INVALID INPUT "
;---------------
;END of PROGRAM
;---------------
.END
HALT
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started