Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- OS LAB assignment 1
- */
- #include <stdio.h>
- #include<stdlib.h>
- #include<conio.h>
- #include <dos.h>
- void interrupt(*Int9Save) (void);
- void interrupt(*Int8Save) (void);
- void interrupt(*Int1Save) (void); /* Pointer to function to store TRAP interrupt */
- // Variables
- volatile unsigned int secISR;
- volatile unsigned int secISR_rec;
- volatile unsigned int secGLOBAL;
- int ISR[256];
- int reqISR;
- int IP;
- int count;
- //Override deafult interrupt
- void interrupt h1(void){
- int idx;
- asm {
- push ax
- mov ax,[BP+2]
- mov IP,ax
- pop ax
- }
- idx=IP/4;
- ISR[idx]++;
- if(count==4){
- if(reqISR>=0 && reqISR<=255)
- printf("ISR[%d] = %d",reqISR,ISR[reqISR]);
- count=0;
- reqISR= -1;
- }
- }
- void interrupt h8(void){
- asm{
- PUSHF
- CALL DWORD PTR Int8Save
- }//asm
- printf("DEBUGGGG\n");
- secGLOBAL--; /*counter*/
- secISR_rec--;
- if (secISR_rec<=0){ // if secISR_rec passed, start again
- secISR_rec=secISR;
- count=0;
- reqISR= -1;
- }
- }
- void interrupt h9(void) {
- unsigned char c1;
- asm{
- PUSH AX
- MOV AH,0
- INT 16h
- MOV c1,AL
- POP AX
- }/* reading the button*/
- if(c1=='i' && count==0){
- count++;
- }
- else if(count==1 && c1<='2' && c1>='0'){
- count++;
- c1=(c1-'0')*100;
- reqISR=c1;
- }
- else if(count==2 && c1<='9' && c1>='0'){
- count++;
- c1=(c1-'0')*10;
- reqISR=reqISR+c1;
- }
- else if(count==3 && c1<='9' && c1>='0'){
- count++;
- c1=(c1-'0');
- reqISR=reqISR+c1;
- }
- }
- void interrupt_counter(int intTime, int time) {
- // give first values
- secISR = intTime*182 / 10;
- secGLOBAL = time*182 / 10;
- secISR_rec=secISR;
- Int9Save = getvect(9); // save old func
- Int8Save = getvect(8); // save old func
- Int1Save = getvect(1); // save old func
- setvect(9, h9); // new func
- setvect(8, h8); // new func
- setvect(1, h1); // new func
- asm{//turn on the trap flag
- pushf
- pop ax
- or ax,100000000B
- push ax
- popf
- }
- }
- void main()
- {
- int i;
- count=0;
- reqISR=-1;
- for(i=0;i<256;i++)
- ISR[i]=0;
- interrupt_counter(5,20);
- while (secGLOBAL>0);
- for(i=0;i<256;i++)
- printf("%d \n",ISR[i]);
- setvect(9, Int9Save); // return to old func
- setvect(8, Int8Save); // return to old func
- setvect(1, Int1Save); // return to old func
- asm{
- pushf
- pop ax
- and ax,1111111011111111B
- push ax
- popf
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement