Question: . text . globl init _ interrupts, isr _ handler, isr _ done init _ interrupts: addi sp , sp , - 8 sw ra

.text
.globl init_interrupts, isr_handler, isr_done
init_interrupts:
addi sp, sp,-8
sw ra,0(sp)
# Print "Initializing Interrupts" message
la a0, init_msg # Load the message address
jal printString # Call the printString subroutine
# Enable Receiver Interrupt
li t0,0x1 # Set enable bit
lui t1,0xFFFF0 # Load base address of RCR
sw t0,4(t1) # Write to RCR to enable interrupts
# Enable global interrupts
csrsi mstatus, 0x8 # Set MIE bit in mstatus
csrsi mie, 0x800 # Enable external interrupts in mie
lw ra,0(sp)
addi sp, sp,8
ret
isr_handler:
addi sp, sp,-16 # Allocate stack space
sw ra,0(sp) # Save return address
sw s0,4(sp) # Save callee-saved register s0
# Step 1: Check the Ready Bit
lui t0,0xFFFF0 # Load base address of RCR
lw t1,0(t0) # Read Receiver Control Register (RCR)
andi t2, t1,0x1 # Check Ready Bit (bit 0)
beqz t2, isr_done # Exit if no key is ready
# Step 2: Read the Key Pressed
lw t3,0(t0) # Load the key from Receiver Data Register (RDR)
mv a0, t3 # Move key to a0 for printing
# Step 3: Print the Key Pressed
la a1, key_msg # Load "Key Pressed is: " message
jal printString # Print the message
jal printChar # Print the key (a0 contains the key)
# Step 4: Increment Persistent Counter
la s0, int_count # Load address of counter in memory
lw t4,0(s0) # Load current counter value
addi t4, t4,1 # Increment counter by 1
sw t4,0(s0) # Store updated counter back to memory
# Step 5: Restart Main After 5 Key Presses
li t5,5 # Compare counter with 5
bne t4, t5, isr_done # Skip if not equal to 5
sw zero, 0(s0) # Reset counter to 0
la t6, main_start # Load the start address of main
csrw mepc, t6 # Modify return address to restart main
isr_done:
lw s0,4(sp) # Restore callee-saved register
lw ra,0(sp) # Restore return address
addi sp, sp,16 # Deallocate stack space
uret # Return from interrupt
.data
KBSR: .word 0xFFFF0000
RDR: .word 0xFFFF0004
key_msg: .string "
Key Pressed is: "
init_msg: .string "
Initializing Interrupts
"
newline: .string "
"
last_key: .word 0 # Persistent storage for last key Error in D:\225-Agn7.2\isr.asm line 18 column 11: "mstatus": operand is of incorrect type
Error in D:\225-Agn7.2\isr.asm line 19 column 11: "mie": operand is of incorrect type
Error in D:\225-Agn7.2\isr.asm line 56 column 10: "mepc": operand is of incorrect type
Assemble: operation completed with errors. I get these errors using rars 1.6. 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
********************
. text . globl init _ interrupts, isr _ handler,

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!