Embed
Email

Bilgi University

Document Sample

Shared by: linzhengnd
Categories
Tags
Stats
views:
0
posted:
12/19/2011
language:
pages:
5
Bilgi University

Comp 371 Final Examination

7 February 2002



READ ALL THE QUESTIONS BEFORE YOU START. ANSWER THE

QUESTIONS AND PARTS OF QUESTIONS YOU FIND EASY FIRST,

BEFORE SPENDING A LOT OF TIME ON PROBLEMS YOU FIND

DIFFICULT.



THE MARKS FOR EACH PART OF EACH QUESTION ARE SHOWN IN []

BRACKETS. TOTAL MARKS 100.





YOU HAVE ONE HOUR





WRITE YOUR ANSWERS IN PEN, NOT PENCIL.

CROSS OUT ERRORS WITH A SINGLE LINE.

LIST THE QUESTIONS AND PARTS OF QUESTIONS YOU HAVE ANSWERED

ON THE FRONT OF YOUR ANSWER PAPER AS INSTRUCTED.

IF YOU HAVE DIFFICULTY EXPRESSING YOURSELF IN ENGLISH, A NEAT

CLEARLY LABELLED DIAGRAM MAY HELP.

1. [25]

Consider the following fragment of Intel x86 assembler code (16 bit).





;find the greatest element in an integer array



mov ax,0 ; zero the accumulator

mov di, offset intarray ; address of intarray

mov cx,COUNT ; loopcounter

L1:

mov bx,[di] ; get the next integer

add di,2 ; point to next integer

sub ax,bx ; is ax > bx ?

ja L2 ; jump if it is

mov ax,bx ; move the greater value to ax

L2:

loop L1 ; repeat until CX = 0







(a) The program has several bugs. Identify them and correct them. State your

assumptions. (the task to be performed is ambiguously defined !) [15]

(c) Rewrite the program to do the same job correctly without using the loop

instruction.[5]

(d) Criticise the comments for the program. Suggest some more meaningful

comments.[5]

2. [25]



The program fragment in Question 1 is to be used to implement an assembler routine

to be called from the C language to add up the elements of an integer array.



The definition for the procedure will be



int maxelem (int * arr, int len);



(a) Write the necessary additional code including all necessary saving and restoring of

registers to allow the program fragment in Question 1 (as corrected) to be used in this

way. Write out the entire resulting routine as your answer. State carefully any

memory model assumptions you make [15]



(b) the following C function is used to print out the nodes of a binary tree. The tree

represents an algebraic expression with the internal nodes representing arithmetic

operators and the leaves of the tree symbols. The print out is in reverse polish format.

Show the contents of the stack at the moment before printf is called for each call to

printf as the function is used to print out the tree. The diagram showing the stack

contents should include the parameters for printf.



struct node

{

char label;

node * left;

node * right;

}



void printrp (mode * tree)

{

if (node)

{

printrp(tree -> left);

printrp(tree -> right);

printf(“ %c ”,tree - > label);

}

}



The tree to be printed is this

+

/ \

* C

/ \

A -

/ \

D E

3. [25]



(a) A processor witha four stage pipeline goes four times as fast. True or false?

Discuss.[5]

(b) Explain with a diagram the stages in the retrieval of an item of data when a set

associative cache is in use (i) when the data item is found in the cache (ii) when the

data item is not found in the cache. [10]

(c) If a cache memory is twenty times faster than the main memory it is cacheing,

Under what conditions will the average retrieval time of the combined memory be 0.3

times the average retrieval time of the main memory without a cache? Under what

circumstances will it be 0.07 times? [10]



4.[25]

Consider the following assembler program. Where you can not know numbers for the

answers you will need to give descriptions.



(a) Write out the contents of the stack immediately after the execution of the

instructions at points ****A,****B, ****X, ****Y, ****Z [10]

(b) Write out the contents for the interrupt vectors for interrupts 09h,10h and 21h

immediately after the execution of the instructions at points ****E, ****F, ****G [5]

(c) replace the instructions at ****X, ****Y, ****Z, with instructions that do not

puah anything onto the stack but allow the program to work correctly.[10]

;------------------------------------------------------------------------------

; This is a COM TSR program.

;------------------------------------------------------------------------------



.MODEL tiny

.CODE

ORG 100h

begin: jmp main



;message string doesn't need to contain $.

;Because int 21h will not be used to show string.



message db 'Your TSR program (new Interrupt Handler) gained the

control'

old_address dd ?



main:

jmp initialize_TSR



TSR_part_of_the_program: ;****A

push ax ; Save register content before using it

push bx ; Save register content before using it

push cx ; Save register content before using it

push dx ; Save register content before using it

push es ; Save register content before using it

push bp ; Save register content before using it



in al, 60h ; Get keyboard code from port 60h ****C

cmp al, 01 ; Is it ESC

jne TSR_part_exit ; If it is not ESC continue

;by calling original handler



; If the keyboard code is equal to ESC key code, show the message

mov ax, cs

mov es, ax ; SEGMENT address of the string

mov bp, OFFSET cs:message ; OFFSET address of the string



mov ah, 13h ; Write string subfunction no

mov al, 0 ; Do not move cursor

mov bh, 0 ; Video page number

mov bl, 10100100b ; Attribute (BLINK + GREEN bckgr + RED frg)

mov cx, 59 ; String length

mov dh, 12 ; Row number

mov dl, 10 ; Column number

int 10h ; Call video interrupt to write string *****B



TSR_part_exit:

pop bp ; Restore register content before calling the original handler

pop es ; Restore register content before calling the original handler

pop dx ; Restore register content before calling the original handler

pop cx ; Restore register content before calling the original handler

pop bx ; Restore register content before calling the original handler

pop ax ; Restore register content before calling the original handler



; Call original handler before exiting new interrupt handler

pushf ; Simulate original interrupt by

;pushing flag register ****X

call dword ptr cs:old_address ; Call original interrupt handler ****Y

iret ; Return from interrupt handler ****Z



initialize_TSR:

cli ; CPU cannot accept external intterrupts any more

; Ensures that this process will not be interrupted



mov ah, 35h ;Get Interrupt vector

mov al, 09h ;for int 09h

int 21h ;via int 21h ****E



mov word ptr old_address, bx ; Save original handler's IP and

mov word ptr old_address[2], es ; CS values



mov ah, 25h ; Set new

mov al, 09h ; int 09h handler address

mov dx, OFFSET TSR_part_of_the_program ; as TSR_part_of_the_program

int 21h ; via int 21h ****F



mov dx, OFFSET initialize_TSR ; TSR part size of the program must

;be in DX as paragraph count

mov cl, 4 ; for PARAGRAPH(=16 bytes) conversion

shr dx, cl ; This is equal to (dx = dx / 16)

inc dx ; PLUS 1 to obtain correct PARAGRAPH value

mov ah, 31h ; to end of a TSR program

mov al, 0 ; TSR return code

sti ; CPU can accept external interrupts

int 21h ; Call DOS to Terminate and Stay Resident ****G



END begin



Related docs
Other docs by linzhengnd
Just Wright
Views: 0  |  Downloads: 0
Property and Insurance Services _PAIS_
Views: 0  |  Downloads: 0
Module 8 Unit3
Views: 0  |  Downloads: 0
Navy Response to EPA Comments on the
Views: 0  |  Downloads: 0
EALING LOCAL BUSINESS PARTNERSHIP
Views: 3  |  Downloads: 0
Hotel Sankara Nairobi
Views: 0  |  Downloads: 0
SERGIO NELSON MANNHEIMER
Views: 0  |  Downloads: 0
C-3 Rides 2010 v3a
Views: 0  |  Downloads: 0
Quality of life_ quality for life.
Views: 0  |  Downloads: 0
Intermodal freight transport-wikipedia
Views: 1  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!