(Solved) : 1 Write Trap Routine Readint Prompts Integer Input Reads Integer Number Keyboard Echoes Mo Q30331471 . . .
1. Write a TRAP Routine (READINT) that prompts for an integerinput, reads an integer number from the keyboard, echoes it on themonitor and returns the input number’s decimal value in R0 to themain program. This trap routine will be invoked by the trapinstruction:
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 ofdigits followed by a new line character (ascii 0A)
Trap x26 must display an error message and HALT if the inputcharacter is not a digit.
READINT can use LC3’s existing TRAP instructions for I/O
2. Write a subroutine, DisplayInt that displaysthe content of R0 as an integer number.
(Note that R0 does not necessarily contain 1 digit)
3. Write a subroutine, Multiply that computesR0=R1*R2.
(Note that to compute prod=m*n, you can initialize prod to 0 andthen add m to prod, n times)
4. Complete and use the following template to write a mainprogram that will test the above routines.
;; Author: Your name (Required!!)
;; Load address of READINT into the System Control Block atx26
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
DiISPLAYINT ;;code to implement DisplayInt
.END
Make sure that READINT, MULTIPLY and DISPLAY do not have anyside effects (i.e before return, they must restore the value of theregisters they use to their original values, except the registerthat contains their output parameter)
Expert Answer
Answer to 1 Write Trap Routine Readint Prompts Integer Input Reads Integer Number Keyboard Echoes Mo Q30331471 . . .
OR