Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ASCII to Decimal Conversion THIS SHOULD BE WRITTEN IN LC-3 ASSEMBLY LANGUAGE. Ge

ID: 656712 • Letter: A

Question

ASCII to Decimal Conversion

THIS SHOULD BE WRITTEN IN LC-3 ASSEMBLY LANGUAGE.

Get 4 ASCII keys from the keyboard representing a single four digit number and translate that number into decimal. At the end I want a decimal number stored in register 0. Get each digit using TRAP 20 then store them.

As an example, if the user types in 0 then 1, then 2, then 5, you have to translate the ASCII codes 30, 31, 32, 35 into the decimal number 125.

The number can be entered as decimal or hex digits. If the first char is X assume hex.

Assume only capital letters will be entered for hex values. Assume good input. That is you can assume the user will only type in 0-9, A-F, X. Assume four numbers. The number 5 will have to be entered as the characters 0005.

I want you to use the procedure I have outlined below. Don't add extra error detection. Don't add extra characters.

1. Create a subroutine named GET_NUM

2. GET_NUM must get a four digit number from the user and convert the ASCII characters to a binary number. That number should be stored in R0 at the end of the subroutine.

3. GET_NUM must save and restore all registers used.

4. Read a character from the keyboard using TRAP x20 and print it to the screen.

5. If R0 is an X jump to code for hex input.

6. Code for decimal input. (You may use a loop for this if you like.)

a. R0 contains the first character/digit of the number.

b. Convert R0 to a numeric value (it is currently ASCII).

c. Multiply what is in R0 by 1000 and add to sum.

d. Get next character/digit using TRAP x20 and print it to the screen. e. Convert R0 to a numeric value (it is currently ASCII).

f. Multiply what is in R0 by 100 and add to sum. g. Get next character/digit using TRAP x20 and print it to the screen.

h. Convert R0 to a numeric value (it is currently ASCII).

i. Multiply what is in R0 by 10 and add to sum.

j. Get next character/digit using TRAP x20 and print it to the screen.

k. Convert R0 to a numeric value (it is currently ASCII).

l. Add R0 to sum.

m. Put sum in R0

7. Code for hex input.

a. R0 contains X.

b. Get first character/digit using TRAP x20 and print it to the screen.

c. Convert R0 to a numeric value (it is currently ASCII).

d. Multiply what is in R0 by _________ and add to sum (figure it out).

e. Repeat (a - d) for the next three characters/digits.

f. Store sum in R0

8. Below are ASCII values you will need.

Character ASCII Value (hex) 0 30 1 31 2 32 3 33 4 34 5 35 6 36 7 37 8 38 9 39 A 41 B 42 C 43 D 44 E 45 F 46 X 58

Explanation / Answer

Multiply a number by 10

.ORIG X3050

LD R5 , TEN

LD R5, TRAP

AND R0, R0,#0

The Loop

AGAIN AND R0, R0

ADD R5,R5

SUM R5,R0

HALT

NUMBER ASCII

TEN STORE X0020

END

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote