Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program to perform the task described below: Interrupt handler ILOC: S

ID: 3764595 • Letter: W

Question

Write a C program to perform the task described below:

Interrupt handler
ILOC: Subtract SP, SP, #12 Save registers.
Store LINK_reg, 8(SP)
Store R2, 4(SP)
Store R3, (SP)
MoveControl R2, IPENDING Check contents of IPENDING.
And R3, R2, #4 Check if display raised the request.
Branch_if_[R3]0 TESTKBD If not, check if keyboard.
Call DISR Call the display ISR.
TESTKBD: And R3, R2, #2 Check if keyboard raised the request.
Branch_if_[R3]0 NEXT If not, then check next device.
Call KISR Call the keyboard ISR.
NEXT: Check for other interrupts.
Load R3, (SP) Restore registers.
Load R2, 4(SP)
Load LINK_reg, 8(SP)
Add SP, SP, #12
Return-from-interrupt
Main program
START: Set up parameters for ISRs.
Move R2, #2 Enable interrupts in
StoreByte R2, KBD_CONT the keyboard interface.
Move R2, #4 Enable interrupts in
StoreByte R2, DISP_CONT the display interface.
MoveControl R2, IENABLE
Or R2, R2, #6 Enable interrupts in
MoveControl IENABLE, R2 the processor control register.
MoveControl R2, PS
Or R2, R2, #1
MoveControl PS, R2 Set interrupt-enable bit in PS.
next instruction
Keyboard interrupt-service routine
KISR:
...
Return
Display interrupt-service routine
DISR:
...
Return

Explanation / Answer

#include <stdio.h>
#include <signal.h>

void sighup(); /* routines child will call upon sigtrap */
void sigint();
void sigquit();

main()
{ int pid;

/* get child process */

   if ((pid = fork()) < 0) {
        perror("fork");
        exit(1);
    }
  
   if (pid == 0)
     { /* child */
       signal(SIGHUP,sighup); /* set function calls */
       signal(SIGINT,sigint);
       signal(SIGQUIT, sigquit);
       for(;;); /* loop for ever */
     }
else /* parent */
     { /* pid hold id of child */
       printf(" PARENT: sending SIGHUP ");
       kill(pid,SIGHUP);
       sleep(3); /* pause for 3 secs */
       printf(" PARENT: sending SIGINT ");
       kill(pid,SIGINT);
       sleep(3); /* pause for 3 secs */
       printf(" PARENT: sending SIGQUIT ");
       kill(pid,SIGQUIT);
       sleep(3);
     }
}

void sighup()

{ signal(SIGHUP,sighup); /* reset signal */
   printf("CHILD: I have received a SIGHUP ");
}

void sigint()

{ signal(SIGINT,sigint); /* reset signal */
   printf("CHILD: I have received a SIGINT ");
}

void sigquit()

{ printf("My DADDY has Killed me!!! ");
exit(0);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote