Help With this please write an LC-3 program that produces the base 16 representa
ID: 3571772 • Letter: H
Question
Help With this please
write an LC-3 program that produces the base 16 representation of a number of integers that are entered at the keyboard. You will use the extended trap for reading integers: TRAP xFB which reads an integer entered at the keyboard and places the integer value into R0.
Your program should continuously prompt the user for an integer from the keyboard. If the integer entered is 0 the program is to terminate. Each integer should be displayed, followed by the hexadecimal representation, such as shown below.
Sample program execution:
Be careful to test your program vigorously to ensure that it handles ALL valid 16 bit integers.
Explanation / Answer
.ORIG x3000
AGAIN LEA R0, PROMPT ;Display the input prompt
TRAP xFB
ADD R0, R0, #0 ;Exit if the input integer is0
BRZ EXIT
AND R1, R1, #0 ;R1 = 16 (output base 16 HEXADECIMAL)
ADD R1, R1, #15
ADD R1, R1, #1
TRAP x22 ;Print the integer in hexadecimal
BRnzp AGAIN
EXIT ;Loop exit point
TRAP x25 ;HALT program execution
PROMPT .STRINGZ "Enter an unsigned integer (0 to quit)>"
.END
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.