Coal Final Solved Spring 2018 Fast LHR
Coal Final Solved Spring 2018 Fast LHR
Question1. [2x10 Marks] Tick the correct answer. No cutting/over-writing. Cutting and over-writing will give you
zero marks. Any answer not clear will also give you zero marks.
i. What will be the value of overflow flag after the following arithmetic statements?
mov ax, 0xD18A
sub ax, 0xFFFF
a. 0
b. 1
ii. While calculating the physical address by adding segment and effective addresses, a 21-bit result (or a
carry-out) would mean which of the following while the logical address was only of 16-bit?
a. There is a segment wraparound but no memory wraparound
b. There is a memory wraparound but no segment wraparound
c. There is a memory and a segment wraparound
d. There is no wraparound at all
v. Ascii values of all the lower case letters have a difference of 0x20 with the ascii of their respective upper
case letter. For example ascii of small ‘a’ is 0x61 and capital ‘A’ is 0x41. Which of the following codes is
converting lower case ascii value to upper case?
viii. Lds si, [bp-2] will load the following values in registers:
a. si will contain [bp+2] and DS will have value of [bp]
b. si will contain [bp-2] and DS will have value of [bp-4]
c. si will contain [bp+2] and DS will have value of [bp-2]
d. si will contain [bp-2] and DS will have value of [bp]
ix. Which of the following statement has the same effect as these two valid instructions?
dec cx
jnz l3
a. rep stosb
b. retf
c. loop l3
d. iret
Question2. [20 Marks] Write an assembly program to find the minimum length of a string in an array of 20 strings
given in DS. All strings are null terminated. The program places the minimum length found in dx register. You have
to do this question using string instructions only but you cannot use cmpsb or cmpsw.
For example:
arraystr: db 'hello',0,'class room',0, 'is',0,'language',0
For this array dx will have value 2 at the end of program.
mov al, 0
push ds
pop es
l1:
dec si
cmp si, 0
je exit
mov bx, cx
repne scasb
sub bx, cx
dec bx
cmp bx, dx
jae l1
mov dx, bx
jmp l1
exit:
The program at all times keeps track of a current_slot_number (between 0 and 5) to know which slot is currently
selected.
Note: the Scan Codes of L and R keys are: 0x46 and 0x33 respectively.
You are only required to write the timer and keyboard ISRs, and declare the necessary variables in your program.
You do not need to write the code to hook the interrupts or create TSR etc. We will not mark any redundant code.
Turn: dw 1
Position: dw 0xb800
Name: db ‘player’
Win: db ‘wins’
Part A) The current scheduling algorithm implemented in example 10.2 executes each process for a fixed period of
time, suspends it and then starts next process in the list. Your task is to change the scheduling algorithm to
“priority based scheduling”. Whenever a task is created it is assigned a priority number between 1 and 4 (4
meaning highest priority). The scheduler works such that it allows every next task to run for thrice as much timer
ticks as its priority. So for example, if a task has priority 4, the scheduler allows it to run for 4x3=12 timer ticks.
When the task has run for its assigned number of timer ticks the scheduler suspends the task (just like in example
10.2) and moves on to the next task. The scheduler keeps doing this for all tasks infinitely.
For task 0, its execution time is 1 timer tick only and has no priority.
For this part you can assume that a function “generate_random_priority” is already defined and given to you
which returns a priority number in ax register.
Note: Do not copy the whole multitasking code. This will earn you zero marks. Just modify the changes required in
the code. Your code should be well-commented and it should explain the changes made to the code.
Tickcount: dw 0
In initpcb:
After line 118:
Call generate_random_priority
Mov cl, 3
Mul cl
Mov [pcb+bx+30], ax
In Timer:
Push ds
Push bx
Push cx
Pop ds
Inc word[tickcount]
Shl bx, 5
Push ax
Mov ax, [tickcount]
Cmp ax, [pcb+bx+30]
Je skip2
Skip2:
pop ax
Skip1:
Insert_after:
Push bp
Mov bp, sp
Push a
Mov si, [bp+4] ;the pcb number
Shl si, 5
Mov di, [pcb+si+28] ;next of that pcb
Mov ax, [nextpcb] ;the new inserted
Mov [pcb+si+28], ax ;setting it as next
Mov si, [nextpcb]
Shl si, 5
Mov [pcb+si+28], di ;newpcb’s next is now set
Pop a
Pop bp
Ret 2
Delete_next_pcb:
Push bp
Mov bp, sp
Push a
Exit:
Pop bp
Pop a
Ret 2
GOOD LUCK!