0% found this document useful (0 votes)
74 views

Lab4 Computer Organization

This document contains C code for implementing reset and exception handling functionality in an embedded system. It includes code snippets to jump to the start of the program on reset, save registers and jump to an interrupt handler on exception, and restore registers before returning from the exception. The main program is meant to enable interrupts, display a running sum, and call the interrupt handler when a key press occurs to update the sum.

Uploaded by

binhnhi0007
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Lab4 Computer Organization

This document contains C code for implementing reset and exception handling functionality in an embedded system. It includes code snippets to jump to the start of the program on reset, save registers and jump to an interrupt handler on exception, and restore registers before returning from the exception. The main program is meant to enable interrupts, display a running sum, and call the interrupt handler when a key press occurs to update the sum.

Uploaded by

binhnhi0007
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include "nios2_ctrl_reg_macros.h" /* Define here the addresses of switches, lights and 7-seg displays.

*/ /* Code needed to implement the reset funcionality */ void the_reset (void)__attribute__((section(".reset"))); void the_reset (void) { asm ("movia r2, _start"); /* Go to the start of */ asm ("jmp r2"); /* the program. */ } /* Code needed to deal with exceptions */ void the_exception (void)__attribute__((section(".exceptions"))); void the_exception (void) { asm ("subi sp, sp, 4"); /* Save the contents of */ asm ("stw et, (sp)"); /* the et register. */ asm ("rdctl et, ipending"); /* If external interrupt, */ asm ("beq et, r0, SKIP_EA_DEC"); /* then decrement et */ asm ("subi ea, ea, 4"); /* by 4. */ asm ("SKIP_EA_DEC:"); /* Insert here the code needed to save all registers except r0, et and sp. */ asm ("call INT_HANDLER"); /* Insert here the code to restore all registers except r0 and sp. */ asm ("eret"); } void INT_HANDLER() { /* Insert here the INT_HANDLER code, which has to check if an interrupt */ /* from KEY1 has occurred and in response update the displayed sum. */ } main() { /* Insert here the code for the main program, which has to enable */ /* the desired interrupts. It also has to display the current sum. */ } /* Return from exception. */

You might also like