Question
what is a simple LC3 code that will prompt user to input two numbers (single digit positive numbers), subtract the second from the first and
what is a simple LC3 code that will prompt user to input two numbers (single digit positive numbers), subtract the second from the first and output the operation and answer (more detailed breakdown below) using the template below?
Breakdown: 1. prompt user and read 2 numeric characters using Trapx20 (GETC), echo to console as they are input using OUT, store as character data in separate registers.
2. output to the console the operation: ie. user enters 5 7, output: 5 - 7 = -2
3. once setup printed, convert ASCII of the number to the binary representations of the numbers
4. preform subtraction by taking 2's compliment of second operand and adding, and determine the sign of the result (+/-); if negative determine magnitude of the result (take 2's complement to turn to positive number)
5. convert result to printable character and print it (with a minus sign if it's negative)
no error message needed for invalid input, code will only be tested with single digit positive numbers. Expected example output should be exactly as follows:
ENTER two numbers (i.e. '0'.....'9') ;--------> (they chose 8 and then 4)
8
4
8 - 4 = 4
...
ENTER two numbers (i.e. '0'.....'9') ;-----> (they chose 4 and then 9)
4
9
4 - 9 = -5
so it is the prompt followed by new line (all newlines generated by program NOT user), first input (echo to console and copied to register) then new line, second input (echo to console and copy to different register) then new line, operation is output (using OUTS and PUTS), program completes operation and outputs the answer followed by newline (one space between each character. If answer is negative number ie -4, no space between - and 4 in display output)
Template:
.ORIG x3000 ; Program begins here ;------------- ;Instructions ;-------------
;---------------------------------------------- ;outputs prompt ;---------------------------------------------- LEA R0, intro ; PUTS ; Invokes BIOS routine to output string
;------------------------------- ;INSERT CODE STARTING FROM HERE ;--------------------------------
HALT ; Stop execution of program ;------ ;Data ;------ ; String to explain what to input intro .STRINGZ "ENTER two numbers (i.e '0'....'9') " NEWLINE .STRINGZ " " ; String that holds the newline character
;--------------- ;END of PROGRAM ;--------------- .END
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