CS-220, Practice Exam 2
R. Eckert

1. Suppose we have defined the following data segment:

data    segment
x       db       10
y       dw       4
z       db       3,5,2,7,8,6,1,4,9
data    ends

and that the following code segment program fragent executes:

        mov      ax,data
        mov      ds,ax
        mov      es,ax
        mov      si,y
        lea      bx,z
        mov      al,z[si]
        mov      ah,z[si][bx]
        mov      di,y[bx]
        mov      dl,[bx+5]

What values will be stored in each of the general purpose registers
affected by this program fragment after it executes?

2. Assuming that low memory of an 8086-based computer system is as shown
below, to what physical address (a 5-digit hex number) would control be
transferred when the instruction INT 4 executes? (All numbers are
expressed in hex; in each case the first number is the address and the
second number is the byte that is stored at that address.)

00000 4f    00004 32    00008 e5     0000c a1    00010 37    00014 cc
00001 7b    00005 78    00009 3f     0000d 4b    00011 5d    00015 66
00002 bb    00006 80    0000a 27     0000e 99    00012 0f    00016 91
00003 65    00007 7a    0000b 4f     0000f dd    00013 10    00017 bb

Write some code that will cause control to be transferred to the
instruction stored at physical address 3af6bh whenever any subsequent 
INT 4 is executed.

3. The program fragment given below outputs a pulse (a 1 then a 0) to
a device connected to one of the ports of a certain 8086-based

(A) Under what conditions is the pulse output?

(B) To what port is the pulse sent?

(C) Which bit is used for sending out the pulse?

(D) Assuming a 5 MHz system clock, what is the duration of the pulse?

(E) Explain in words how the pulse is produced.

(Recall that in Intel nomenclature, the least significant bit of an 8-bit
register is called bit-0 and the most significant bit is bit-7).

On an 8086 processor, each iteration of the LOOP instruction requires 
17 system clock pulses.

                 AND    AL,0BFH
                 OUT    57,AL
                 MOV    DX,513H
    XXX:         IN     AL,DX
                 TEST   AL,2
                 JZ     XXX
                 MOV    CX,10
                 OR     AL,40H
                 OUT    57,AL
    YYY:         LOOP   YYY
                 XOR    AL,40H
                 OUT    57,AL
                 JMP    XXX

4. Write some IBM-PC assembly language code that will display a horizontal
line composed of blinking magenta asterisks on a yellow background across
the middle of the screen. The line should go from the left edge of the
screen to its right edge. Assume that the video mode is the default mode
3. You should not use int 10h.

5. On an IBM-PC compatible computer you are to write a routine that will 
output an unending 500 Hz tone, regardless of the processor and system clock 
being used. Write an assembly language routine that will produce that tone.

6. A certain IBM-PC compatible computer is using as its "drive B" a system
in which the diskette is double-sided, 80 tracks per side, 18 sectors per
track, with 512 bytes of information stored on a sector. (A) What is the total 
number of bytes of information that can be stored on the diskette? (B) Write
some assembly language code that will fill track 3, sector 4 of the diskette
with the letter 'A'.

7. Write a C program that will output the elements of an 2D array defined as:

int data[3][5] = { 11, 12, 13, 14, 15, 21, 22, 23, 24, 25, 31, 32, 33, 34, 35 };

in row major order, labeling the columns as 0, 1, 2, 3, 4 and the rows as 0, 1, 2.

The program should then determine and output the average of all the elements 
of the array. The averaging should be done as a function with the following 

int avg(int arr[5][3]);

The output of the program should look like the following:

      0   1   2   3   4
0    11  12  13  14  15
1    21  22  23  24  25
2    31  32  33  34  35
The average of all data is 23