la t0,handler csrw mtvec,t0 # Set trap handler address and mode (0/direct) li t0,0x400 csrc mstatush,t0 # Enable trap handler li t0,0x80 csrw mie,t0 # Enable machine timer interrupt and disable others la t0,mmio csrw 0x801,t0 # Set up MMIO base address lw t1,2(t0) # Read current time addi t1,t1,5 sw t1,10(t0) # Set mtimecmp to 5 seconds in the future csrsi mstatus,8 # Enable interrupts globally wfi # Wait for the interrupt to trigger li a7,10 # Exit program ecall .balign 4 handler: li t1,-1 sw t1,10(t0) # Set mtimecmp to the distant future csrr a0,mcause li a7,1 # Print integer ecall li a0,'\n' li a7,11 # Print character ecall mret mmio: