Implement a simple four function calculator in the LC3 assembly language that wi
ID: 3825355 • Letter: I
Question
Implement a simple four function calculator in the LC3 assembly language that will run on the LC-3 simulator. The LC-3 computer only reads a character at a time but is capable of displaying a string of characters. This calculator program will use multiple subroutines that perform purposes such as reading multi-digit numbers, converting them to integers, performing addition, subtraction, multiplication, or division on these numbers, and displaying the result. The inputs to the calculator will not exceed 4 digits. The user interaction with the calculator is shown below in several example runs:
EXAMPLE RUN 1:
Enter the first operand (SRC1): 34
Enter the second operand (SRC2): 27
Operation (+, -, *, /)? +
Sum is: 61
Continue (Y, N)? Y
Enter the first operand (SRC1): 378
Enter the second operand (SRC2): 237
Operation (+, -, *, /)? -
Difference is: 141
Continue(Y, N)? N
EXAMPLE RUN 2:
Enter the first operand (SRC1): 34
Enter the second operand (SRC2): 75
Operation (+, -, *, /)? -
Difference is: -41
Continue(Y, N)? N
EXAMPLE RUN 3:
Enter the first operand (SRC1): 24
Enter the second operand (SRC2): 18
Operation (+, -, *, /)? *
Product is: 432
Continue(Y, N)? N
Explanation / Answer
;initializes all registers to zero
AND R0, R0, #0
AND R1, R1, #0
AND R2, R2, #0
AND R3, R3, #0
AND R4, R4, #0
AND R5, R5, #0
AND R6, R6, #0
AND R7, R7, #0
;this block will ask for user input then display it to the monitor
NEXTCHARACTER GETC
OUT
;reads input and determines whether or not it is a valid character
;Space?
LEA R0, PROMPT ;Save the location of the prompt
PUTS ;Print the prompt to the screen
GETC ;Store the character into R0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.