Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write it in LC-3, thank you very much! provided code: .ORIG x3000 ;------------- ;Instructions ;------------- ; output intro prompt ; Set up flags, counters,

Please write it in LC-3, thank you very much!

image text in transcribed

image text in transcribed

image text in transcribed

provided code:

.ORIG x3000 ;------------- ;Instructions ;-------------

; output intro prompt ; Set up flags, counters, accumulators as needed

; Get first character, test for ' ', '+', '-', digiton-digit ; is very first character = ' '? 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

; 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! HALT

;--------------- ; Program Data ;---------------

introPromptPtr .FILL xB000 errorMessagePtr .FILL xB200

.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 of PROGRAM ;--------------- .END

;------------------- ; 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 ( 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 Tasks 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 the number. - 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 (' nn=x0A ), or when you reach 5 input digits: - For example, if the user types '2', then Rx will contain #2 = b00000000 00000010 - If the user then types ' 3 ', making the string now read " 23 ", then Rx will contain 2x#10+3=#23= b0000 000000010111 If the user then types ' 4 ', making the string read " 234 ", then Rx will contain #23#10+4=#234=b0000000011101010 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]. xpected / Sample output Output - Prompt - 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 b0001 110001001110 (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 ! (Valid input with a negative sign)

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

More Books

Students also viewed these Databases questions

Question

define what is meant by the term human resource management

Answered: 1 week ago