CS401 Assignment No 4 Spring 2012 solution

Question No 1:

a)      Interrupts are used to invoke system activities that have to be performed on regular basis. Programmable interval timer (PIT) is using triggers that interrupt when it reaches the programmed count. Find out whether the frequency of Programmable Interval Timer (PIT) is fixed or not (for IBM PC compatibles)? Also give example how time tick generated through Programmable Interval Timer?               (Marks 10)


Another very important peripheral device is the programmable interval timer (PIT) chip numbered 8254. This chip has a precise input frequency of 1.19318 MHz. This frequency is fixed regardless of the processor clock.


; display a tick count on the top right of screen
[org 0x0100]
jmp start
tickcount: dw 0
; subroutine to print a number at top left of screen
; takes the number to be printed as its parameter
printnum: push bp
mov bp, sp
push es
push ax
push bx
push cx
push dx
push di
mov ax, 0xb800
mov es, ax ; point es to video base
mov ax, [bp+4] ; load number in ax
mov bx, 10 ; use base 10 for division
mov cx, 0 ; initialize count of digits
nextdigit: mov dx, 0 ; zero upper half of dividend
div bx ; divide by 10
add dl, 0x30 ; convert digit into ascii value
push dx ; save ascii value on stack
inc cx ; increment count of values
cmp ax, 0 ; is the quotient zero
jnz nextdigit ; if no divide it again
mov di, 140 ; point di to 70th column
nextpos: pop dx ; remove a digit from the stack
mov dh, 0x07 ; use normal attribute
mov [es:di], dx ; print char on screen
add di, 2 ; move to next screen location
loop nextpos ; repeat for all digits on stack
pop di
pop dx
pop cx
pop bx
pop ax

pop es
pop bp
ret 2
; timer interrupt service routine
timer: push ax
inc word [cs:tickcount]; increment tick count
push word [cs:tickcount]
call printnum ; print tick count
mov al, 0x20
out 0x20, al ; end of interrupt
pop ax
iret ; return from interrupt
start: xor ax, ax
mov es, ax ; point es to IVT base
cli ; disable interrupts
mov word [es:8*4], timer; store offset at n*4
mov [es:8*4+2], cs ; store segment at n*4+2
sti ; enable interrupts
mov dx, start ; end of resident portion
add dx, 15 ; round up to next para
mov cl, 4
shr dx, cl ; number of paras
mov ax, 0x3100 ; terminate and stay resident
int 0x21


b)      Write down the instructions those are used to inform the PIC about the end of an interrupt?    (Marks 5)


   At the end of servicing the interrupt the handler should inform the PIC that it is completed so that lower priorty interrupts can be sent from the PIC. This signal is called an End Of Interrupt (EOI) signal and is sent through the I/O ports of the interrupt controller.

c)      PCB (Process Control Block) is a space where all registers of a task are stored. Describe how many bytes are needed to structure PCB and also explain different purposes of these bytes?                       (Marks 5)


In our next example we will save all 14 registers and the stack as well. 28 bytes are needed by these registers in the PCB. We add more space to make size 32, a power of 2 for easy calculations. One of these words used to form a linked list of the PCBs so that strict ordering of active PCBs is not necessary.=