Sponsored Links


Results 1 to 2 of 2

Thread: cs401 assignment no 4 idea solution on 3rd of January

  1. #1
    Administrator
    Join Date
    Oct 2011
    Posts
    468

    Icon14 cs401 assignment no 4 idea solution on 3rd of January

    Sponsored Links1



    Sample output (each output line is result of pressing s key):
    2 1 4 3 6 5 8 7 10 9
    1 2 4 3 6 5 8 7 10 9
    1 2 4 3 6 5 8 7 10 9
    1 2 3 4 6 5 8 7 10 9
    .
    .
    .
    .
    1 2 3 4 5 6 7 8 9 10


    HINT:
    For checking whether s key is pressed, you need to hook keyboard interrupt.

    Sponsored Links
    Attached Files Attached Files
    03009520262
    Rabeel Website

  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    SOLUTION:

    001 ; elementary multitasking of two threads

    002 [org 0x0100]

    003 jmp start

    004

    005 ; ax,bx,ip,cs,flags storage area

    006 taskstates: dw 0, 0, 0, 0, 0 ; task0 regs

    007 dw 0, 0, 0, 0, 0 ; task1 regs

    008 dw 0, 0, 0, 0, 0 ; task2 regs

    009

    010 current: db 0 ; index of current task

    011 chars: db ‘\|/-’ ; shapes to form a bar

    012

    013 ; one task to be multitasked

    014 taskone: mov al, [chars+bx] ; read the next shape

    015 mov [es:0], al ; write at top left of screen

    016 inc bx ; increment to next shape

    017 and bx, 3 ; taking modulus by 4

    018 jmp taskone ; infinite task

    019

    020 ; second task to be multitasked

    021 tasktwo: mov al, [chars+bx] ; read the next shape

    022 mov [es:158], al ; write at top right of screen

    023 inc bx ; increment to next shape

    024 and bx, 3 ; taking modulus by 4

    025 jmp tasktwo ; infinite task

    026

    027 ; timer interrupt service routine

    028 timer: push ax

    029 push bx

    030

    031 mov bl, [cs:current] ; read index of current task

    032 mov ax, 10 ; space used by one task

    033 mul bl ; multiply to get start of task

    034 mov bx, ax ; load start of task in bx

    035 vusolutions .com

    036 pop ax ; read original value of bx

    037 mov [cs:taskstates+bx+2], ax ; space for current task

    038 pop ax ; read original value of ax

    039 mov [cs:taskstates+bx+0], ax ; space for current task

    040 pop ax ; read original value of ip

    041 mov [cs:taskstates+bx+4], ax ; space for current task

    042 pop ax ; read original value of cs

    043 mov [cs:taskstates+bx+6], ax ; space for current task

    044 pop ax ; read original value of flags

    045 mov [cs:taskstates+bx+8], ax ; space for current task

    046

    047 inc byte [cs:current] ; update current task index

    048 cmp byte [cs:current], 3 ; is task index out of range

    049 jne skipreset ; no, proceed

    050 mov byte [cs:current], 0 ; yes, reset to task 0

    051

    052 skipreset: mov bl, [cs:current] ; read index of current task

    053 mov ax, 10 ; space used by one task

    054 mul bl ; multiply to get start of task

    055 mov bx, ax ; load start of task in bx

    056

    057 mov al, 020

    058 out 020, al ; send EOI to PIC

    059

    060 push word [cs:taskstates+bx+8] ; flags of new task

    061 push word [cs:taskstates+bx+6] ; cs of new task

    062 push word [cs:taskstates+bx+4] ; ip of new task

    063 mov ax, [cs:taskstates+bx+0] ; ax of new task

    064 mov bx, [cs:taskstates+bx+2] ; bx of new task

    065 iret ; return to new task

    066

    067 start: mov word [taskstates+10+4], taskone ; initialize ip

    068 mov [taskstates+10+6], cs ; initialize cs

    069 mov word [taskstates+10+8], 00200 ; initialize flags

    070 mov word [taskstates+20+4], tasktwo ; initialize ip

    071 mov [taskstates+20+6], cs ; initialize cs

    072 mov word [taskstates+20+8], 00200 ; initialize flags

    073 mov word [current], 0 ; set current task index

    074

    075 xor ax, ax

    076 mov es, ax ; point es to IVT base

    077 cli

    078 mov word [es:8*4], timer

    079 mov [es:8*4+2], cs ; hook timer interrupt

    080 mov ax, 0xb800

    081 mov es, ax ; point es to video base

    082 xor bx, bx ; initialize bx for tasks

    083 sti

    084



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 10-11-2012, 04:54 PM
  2. Replies: 0
    Last Post: 01-23-2012, 09:30 PM
  3. Replies: 2
    Last Post: 01-04-2012, 01:15 PM
  4. Replies: 0
    Last Post: 12-28-2011, 05:30 PM
  5. cs401 idea solution july 2011
    By msmunirm1 in forum GDB Discussion
    Replies: 4
    Last Post: 07-09-2011, 01:44 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft