0% found this document useful (0 votes)
69 views3 pages

Multi

This document describes a program that implements multitasking of two tasks on an x86 system. It defines two tasks, taskone and tasktwo, that each display a character shape on the screen by incrementing through a character array. A timer interrupt handler switches between the tasks by saving and restoring their register states stored in an array. It initializes the tasks' states and installs the timer interrupt handler to begin multitasking.

Uploaded by

jay_jal
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 DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views3 pages

Multi

This document describes a program that implements multitasking of two tasks on an x86 system. It defines two tasks, taskone and tasktwo, that each display a character shape on the screen by incrementing through a character array. A timer interrupt handler switches between the tasks by saving and restoring their register states stored in an array. It initializes the tasks' states and installs the timer interrupt handler to begin multitasking.

Uploaded by

jay_jal
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 DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Example 11.

1
001 ; elementary multitasking of two threads[org 0x0100]
002 jmp start ; ax,bx,ip,cs,flags storage areataskstates: dw 0, 0, 0, 0, 0
003 ; task0 regsdw 0, 0, 0, 0, 0
004 ; task1 regsdw 0, 0, 0, 0, 0
005 ; task2 regs current: db 0
006 ; index of current taskchars: db ‘\|/-
007 ; shapes to form a bar
008 ; one task to be multitaskedtaskone
009 : mov al, [chars+bx]
010 ; read the next
011 shapemov [es:0], al
012 ; write at top left of screen
013
014
015

016 inc and jmp bx bx, ; increment to next shape


017 3taskone ; taking modulus by 4
018 ; infinite task
019
020 mov al, [chars+bx]
; second task to be multitasked task two:
021 mov [es:158],
; read the next shape
022 alinc bx and bx,
; write at top right of screen
023 jmp task two
; increment to next shape
024
; taking modulus by 4
025
; infinite task
026
027 push axpush bx ; timer interrupt service routinetimer:
028
029
030
031 Mov bl, ; read index of current task
032 [cs:current],ax ; space used by one task;
033 mov ax,10 multiply to get start of task
034 mul bl ; load start of task in bx
035 mov bx, ax
036 Popmov ax ; read original value of bx[cs:taskstates+bx+2],
037 Popmov ax ; space for current task
038 popmov ax ; read original value of ax[cs:taskstates+bx+0],
039 popmov ax ; space for current task
040 popmov ax ; read original value of ip[cs:taskstates+bx+4],
041 ; space for current taskax ; read original value of
042 cs[cs:taskstates+bx+6],
043 ; space for current task
044 ; read original value of flags[cs:taskstates+bx+8],
045 ; space for current task
046
047 inc byte [cs:current] ; update current task
048 index cmp byte [cs:current], 3
049 ; is task index out of rangejne skipreset
050 ; no, proceed
051 mov byte [cs:current], 0
; yes, reset to task 0
052 skiprese Mov bl, ; read index of current task;
053 t: [cs:current],ax space used by one task
054 mov ax,10 ; multiply to get start of task
055 mul bl ; load start of task in bx
056 mov bx, ax
057 Mov
058 al,0x200x20 ; send EOI to PIC
059 out al
060 push word [cs:taskstates+bx+8]
061 ; flags of new taskpush word
062 [cs:taskstates+bx+6] ; cs of new task
063 push word [cs:taskstates+bx+4]
064 ; ip of new task
065 mov ax, [cs:taskstates+bx+0]
066 ; ax of new task
mov bx, [cs:taskstates+bx+2]
; bx of new task
Iret ; return to new task
067 068 sMov word ; initialize ip
069 070 t[taskstates+10+
071 072 a4],taskone
073 074 r mov ; initialize csword
t[taskstates+10+
:6], cs
mov ; initialize flags word
[taskstates+10+
8], 0×0200
mov ; initialize ip
[taskstates+20+
4], tasktwo
mov ; initialize csword
[taskstates+20+
6], cs
mov ; initialize flags word
[taskstates+20+
8], 0×0200
mov [current], ; set current task index
0
075 076 Xor ax
077 Mov ax,es
Cli ax
point es to IVT base

078 079 mov word


080 jum [es:8*4], timer
082 083 mov [es:8*4+2]
,cs ; hook timer interrupt ; point es to video base;
mov ax,0xb800 initialize bx for tasks
mov es,ax
xor bx
sti bx
08 Jmp s ;infinite loop

You might also like