Board logo

标题: [原创]dos下进程切换事例 [打印本页]

作者: yaly     时间: 2004-9-7 00:00    标题: [原创]dos下进程切换事例

#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define INTERRUPT 0xfc
unsigned task1[200];
unsigned task2[200];
int l=0;
int h=0;
int num=0;
//void (interrupt far * oldhandler)();
void os_task1(void)
{
while(1)
{
  printf("this 1\n";
   // getchar();
   // sleep(1);
  asm int 0xfc
}
}
void os_task2(void)
{
while(1)
{
  printf("this 2\n";
  // getchar();
  // sleep(1);
  asm int 0xfc
}
}
void interrupt far handler()
{
// printf("this is interrupt";
h++;
printf("num=%d\n",h);
if(l){
l=0;
//pusha
//pop
//                printf("%d\n"",num
/* asm mov bx,offset task2
asm pop ax
asm mov word ptr [bx+2],ax
asm pop ax
asm mov word ptr [bx],ax
// asm popf
  */
  { asm pop ax
  asm pop ax
  asm pop ax
  asm pop ax
  asm mov bx,offset task1
  asm mov ax,word ptr[bx]
  asm push ax
  asm mov ax,word ptr[bx+2]
  asm push ax
//asm pushf
  asm iret
} }
else
{
l=1;
asm pop ax
asm pop ax
asm pop ax
asm pop ax
// asm popf
asm mov bx,offset task2
asm mov ax,word ptr[bx]
asm push ax
asm mov ax,word ptr[bx+2]
asm push ax
  // asm pushf
asm iret
}
}
main()
{
void interrupt far handler();
task1[1]=FP_OFF(os_task1);
task1[0]=FP_SEG(os_task1);
// task2[1]=FP_OFF(os_task2);
// task2[0]=FP_SEG(os_task2);
// os_task1();
// printf("task1[0]=%04x task1[1]=%04x\n",task1[0],task1[1]);
task2[1]=FP_OFF(os_task2);
task2[0]=FP_SEG(os_task2);
setvect(INTERRUPT,handler);
// asm int 0xfc
os_task1();
}
msn:yaly163@hotmail.com
作者: Wengier     时间: 2004-9-8 00:00
沒有說明?