Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LC-3 assembly language assignment The purpose of this assignment is to illustrate how the .FILL pseudo-op performs the task of translating textual numbers (such as

LC-3 assembly language assignment

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 in a signed multi-digit number (max 5 digits) from the keyboard. Convert the string of characters entered (as separate ascii codes for decimal numeric digits) into the 16-bit number they represent, and store the result in R5. The range of acceptable values is [-32768, +32767]; the absence of a sign means the number is positive.

Your Tasks

Your program can be broken down into the following tasks: Read in the + or -. If the character is a -, remember to make the final result negative (i.e. take the 2s complement 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:

Initialize 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:

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

Your code will obviously be tested with a range of different values: Make sure you test your code likewise!

Uhhelp? Try to write this program out in C++/pseudocode before directly tackling it in LC3. Doing so often helps to simplify the process and usually only takes a few minutes to do if you think it through carefully. To mark the distinction between a positive number and a negative one, set a flag (say R5). If the first character is a -, then put a negative number (like #-1) into R5. Otherwise, set R5 to #0 (i.e. non-negative). That way, after you translate the rest of the input characters into the number they represent, you can use a quick IF-statement (like BRn MAKE_NEGATIVE) to toss in the two lines of code it takes to take the 2s complement of the result.

Submission Instructions Submit to GitHub for testing, feedback and grading.

Comments/Feedback Download the results.html file to see your grade and the reasons for any points deducted.

Using the provided template is required.

Not using R5 to hold the result, or the memory address provided in the template, will result in a failing score

Provided template: .ORIG x3000 ; Program begins here

;-------------

;Instructions

;-------------

;-------------------------------

;INSERT CODE STARTING FROM HERE

;--------------------------------

;Example of how to Output Intro Message

;LD R0, introMessage ;Output Intro Message

;PUTS

;Example of how to Output Error Message

;LD R0, errorMessage ;Output Error Message

;PUTS

HALT

;---------------

;Data

;---------------

introMessage .FILL x6000

errorMessage .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_mes .STRINGZ "ERROR INVALID INPUT "

;---------------

;END of PROGRAM

;---------------

.END

;-------------------

;PURPOSE of PROGRAM

;-------------------

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

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

=+Which caste does the delivery man belong to?

Answered: 1 week ago

Question

Write an elaborate note on marketing environment.

Answered: 1 week ago