https://www.google.com/contributor/welcome/?utm_source=publisher&utm_medium=banner&utm_campaign=2376261057261409

Search This Blog

Search with our Site

Custom Search

Sunday, January 8, 2012

cs401 assignment solution fall 2012


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, 0×20
058 out 0×20, 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], 0×0200 ; 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], 0×0200 ; 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
085 jmp $ ; infinite loop



Read more: CS401 Assignment no 4 Solution & Discussion Due Date: 09-01-2012 - Virtual University of Pakistan http://vustudents.ning.com/group/cs401computerarchitectureandassemblylanguageprogra/forum/topics/assagnment-4-cs-401-fall-2011-due-date-9-january-2012#ixzz1ltdx7g82






CS401 Assignment No. 4 Fall 2011

Computer Architecture and Assembly Language Programming

Solution

You are required to write an Assembly Terminate and Stay Resident (TSR) program that will sort an array of numbers 2, 1, 4, 3, 6, 5, 8, 7, 10, 9. The program will perform the following operations.
  • The original array will be shown when the program starts.
  • When user presses s key, the program will sort first two digits of array i.e 2, 1 and display the resulting array on next line.
  • Pressing s key again will sort 2nd and 3rd number in the array if needed and so on.
  • Pressing s key 10 times will show the array sorted as shown in the sample output.
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
.
.
.
.
You are required to write an Assembly Terminate and Stay Resident (TSR) program that will sort an array of numbers 2, 1, 4, 3, 6, 5, 8, 7, 10, 9. The program will perform the following operations.
•        The original array will be shown when the program starts.
•        When user presses s key, the program will sort first two digits of array i.e 2, 1 and display the resulting array on next line.
•        Pressing s key again will sort 2nd and 3rd number in the array if needed and so on.
•        Pressing s key 10 times will show the array sorted as shown in the sample output.
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.
NOTE: You must submit your solution through LMS within due date. No assignment would be accepted through email after deadline.

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
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
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
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, 0×20
058 out 0×20, 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], 0×0200 ; 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], 0×0200 ; 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
085 jmp $ ; infinite loop

 




No comments:

Post a Comment