Question: Part 3 : Interrupts You must now use interrupts to retrieve the key pressed from the keyboard window in the MMIO Display and Keyboard tool.

Part 3: Interrupts
You must now use interrupts to retrieve the key pressed from the keyboard window in the MMIO Display and Keyboard tool.
Create a new file named isr.asm.
The isr.asm file will contain both the ISR initialization subroutine and the handler code.
The initialization subroutine is a user routine that performs the following tasks:
Set the handlers address.
Enable receiving of a device interrupt.
Enable the external device to send interrupts
Enable global interrupt checking.
Prints the message
Initializing Interrupts
to the MMIO window.
You must use the printstring subroutine in MMIO.asm.
Update testint.asm to call your interrupt initialization routine at the start of the program.
No other changes are needed in testint.asm
Create the interrupt service routine:
Remember, all registers in a service routine are treated as callee save (including argument and temp registers)
Unlike an exception handler, an interrupt service routine does not need to modify the epc.
Place the char of the key pressed in the register a0 so the main loop will print the last char typed repeatedly instead of asterisks *.
Do you need to check the ready bit before reading the Data Register?
Do you need to clear the ready bit after reading the Data Register?
Prints the message
Key Pressed is: %c
, to the MMIO window where %c is the key that was pressed.
(yes, printing from an ISR isnt normal, but will demonstrate a point).
Returns from interrupt, restoring all registers modified except a0.
Your code must adhere to the Procedure Calling conventions for your subroutines and service routines.
All subroutines called from the main handler must return to the main handler to return to the user program.
There should only be a single URET in your program.
The ISR itself must preserve all registers used callee or caller save. You may push and pop all caller save registers if you like.
Part 4: Interrupt Hacking
We will change the return from interrupt behavior to do something unsavory.
Change the default return behavior of the Interrupt Service Routine.
Count the number of MMIO interrupts:
You may not use a register to hold the interrupt count between interrupts.
Remember that registers are supposed to be restored after returning.
Hint: Is there a data region that is persistent across subroutine calls?
After 5 key presses, update settings so the ISR will return to the start of main on rather than where you left off.
Reset the counter to zero.
Use URET to exit the handler.
The Key pressed message still prints.
Returns from interrupt using URET, restoring all registers modified except a0.
You need to look at how URET works to change the behavior of URET.
Note: All registers are Callee Save (including argument and temp registers) in an interrupt handler.
Your code must still adhere to the Procedure Calling Conventions for your subroutines.
Example Output
Below is the output of the fully functional program.
Initializing Interrupts
**********
Key Pressed is: 1
11111111111111111111111111111111111111
Key Pressed is: 2
22222222222222222222222
Key Pressed is: 3
3333333333333
Key Pressed is: 4
44444444444444444444444
Key Pressed is: 5
Initializing Interrupts
********************

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!