Question: 1. Write a TRAP Routine (READINT) that prompts for an integer input, reads an integer number from the keyboard, echoes it on the monitor and
1. Write a TRAP Routine (READINT) that prompts for an integer input, reads an integer number from the keyboard, echoes it on the monitor and returns the input numbers decimal value in R0 to the main program. This trap routine will be invoked by the trap instruction:
TRAP x26
For example, TRAP x26 will display
Enter an integer ->
And when 937 is entered as shown below:
Enter and integer -> 937
will return 937 in R0. Note that an integer is a sequence of digits followed by a new line character (ascii 0A)
Trap x26 must display an error message and HALT if the input character is not a digit. READINT can use LC3s existing TRAP instructions for I/O
2. Write a subroutine, DisplayInt that displays the content of R0 as an integer number. (Note that R0 does not necessarily contain 1 digit)
3. Write a subroutine, Multiply that computes R0=R1*R2. (Note that to compute prod=m*n, you can initialize prod to 0 and then add m to prod, n times)
4. Complete and use the following template to write a main program that will test the above routines.
;; Author: Your name (Required!!)
;; Load address of READINT into the System Control Block at x26
Trap x26 ;Read the first integer
;; R1 <- R0
Trap x26 ; Read the second integer
;; R2 <- R0
JSR MULTIPLY
JSR DISPLAYINT
HALT
READINT ;; code to implement Trap 26
MULTIPLY ;; code to implement Multiply
DiSPLAYINT ;;code to implement DisplayInt
.END
Make sure that READINT, MULTIPLY and DISPLAY do not have any side effects (i.e before return, they must restore the value of the registers they use to their original values, except the register that contains their output parameter)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
