CS-220 Practice Exam # 1
R. Eckert

These are the TYPES of questions that could be on the first CS-220 exam:


1. The following assembly language program has been written for the simple
computer we talked about during the second week of class (the one you used 
the simulator with in Lab 1:

address  contents    Assembly Language
--------------------------------------
   9                     ORG   9
 -----
                     x:  DW    3
 -----    -----
                     Y:  DW    4
 -----    -----
                         ORG   0
 -----         
                         LDA   X
 -----    -----
                         MBA
 -----    -----
                         LDA   Y
 -----    -----
                     BB: SUB
 -----    -----
                         JN    AA
 -----    -----
                         JMP   BB
 -----    -----
                     AA: STA   X
 -----    -----
                         HLT
 -----    -----
                         END

(A) Fill in the blanks with the decimal values that would be placed in the 
address and contents fields when this program is assembled into machine 
language.

(B) Assume the machine code for this program has been loaded into memory.
Complete the following table of values that would be stored in the various
registers and on the buses, as well as the active control signals during 
each of the first ten clock pulses of the fetch-decode-execute cycle when 
the computer's clock starts. 

Clock  PC  MAR  MDR  ACC  ALU  NF  B  IR   Ring   Active  
Pulse                                      Pulse  Signals
----------------------------------------------------------
0      0    0    0    0    0   0   0  0      0    EP,LM    
1
2
3
4
5
6
7
8
9
10
 
(C) The figure below is a diagram of the simple computer's hard-wired control 
unit. You are to highlight all signal lines, AND gates, OR gates, and flip-flops 
that are active (are high), as well as write in the values that are contained in 
the Instruction Register, the Negative Flag, and the "Active Control Signals" 
boxes in one of these diagrams at each of the following moments in the execution 
of the example program:

Ring Pulse 0 of the "fetch" of the second LDA instruction in the program
Ring Pulse 2 of the "fetch" of the SUB instruction
Ring pulse 5 of the second LDA instruction
Ring pulse 3 of the SUB instruction the first time it is executed
Ring pulse 3 of the JN instruction the first time it is executed
Ring pulse 3 of the JN instruction the second time it is executed
Ring pulse 0 of the next instruction fetched
Ring pulse 4 of the STA instruction
Ring pulse 5 of the STA insturction

(D) After the program is done executing, some value was stored at some address
in memory. What is the value stored and what is the address?




2. (A) Convert -58.40625 (decimal) to the 32-bit IEEE short real
floating point format discussed in class. Your result should be
expressed in hex.

(B) The number 43572000h is a hexadecimal representation of a 32-
bit IEEE short real number. Determine the decimal value of this
number.


3. Assume that the 8086 registers contain the following data:

AX = 19 (decimal),  CX = 2,  BH = 10 (decimal),  BL = -3

What will be the contents of any register changed by each of the
instructions given below? Express your answers in hex.

If the zero flag, the carry flag, the parity flag, the sign flag, and/or
the overflow flag are affected by the instruction, give the new status (1
or 0) after execution. Each instruction is independent. In other words, the
registers always contain the same initial values given above before
execution of each instruction.

(A) ADD AX,127

(B) CMP CX,3

(C) SHR BH,CL

(D) SUB BH,10

(E) TEST AL,0Fh

(F) XOR BH,AL

(G) MUL CL

(H) IDIV BL


4. The following data is found in an 80X86 assembly language
program:

data    segment
az      db     3 dup(3)
bz      dw     0A32Eh,3Fh,1000
cz      db     'HELLO'
dz      dd     0FA3672B0h
ez      dw     -2
fz      db     4,2,3Ah,11110000b,23,95
data    ends

(A) Show exactly what is stored in each byte of this data segment. The
contents of each byte should be expressed in hexadecimal. The best way to
do this is to fill in the blanks of the following diagram (which represents
what DEBUG would display if a memory dump were done):

xxxx:0000  ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___

xxxx:0000  ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___

(B) What would be the contents of the register affected if each of the
following instructions were executed? Express your answers in hexadecimal?

  mov    ax,bz
  mov    bl,fz+2
  mov    si,word ptr cz+3
  mov    bh,byte ptr dz+1
  mov    dl,byte ptr dz+4
  mov    di,bz+8


5. The following is output from the -r and -d DEBUG commands after a
certain 8086 program has run with a breakpoint set.

-r
AX=200F  BX=0002  CX=0049  DX=0001  SP=0020  BP=0000  SI=0000  DI=0000
DS=3B49  ES=3B37  SS=3B47  CS=3B4A  IP=000D   NV UP EI PL NZ NA PO NC
3B4A:000D F6F3          DIV     BL

-d0,f
3B49:0000  0F 20 06 5B 66 1F 15 2A-37 6B CC 5D 00 21 3D 18   . .[f...........

The answer to each of the following questions should be expressed in hex:

(A) What is the offset of the next instruction to be executed?

(B) What is the physical address (a 5-digit hex number) of the next
instruction to be executed?

(C) What is the machine language code for the next instruction to be
executed?

(D) What is currently stored in BH register?

(E) What byte value is stored at offset 9 in the data segment?

(F) What is the physical address of that byte?

(G) What is the status (0 or 1) off the Carry Flag, the Zero Flag, and the
Parity Flag?

(H) At what physical address does the stack segment begin?

(I) If the next instruction to be executed were a CALL to a near procedure
at offset 005Eh instead of the DIV instruction, what would be the new
contents of any registers changed by execution of that instruction. (Assume
that the registers are as indicated above before the CALL is executed.)


6. A variable called 'flag' is defined with a db. Write an 80X86 assembly
program fragment that will do one of the following, depending upon the
contents of 'flag':

If 'flag' contains the ASCII code for an 'M' it should multiply the contents
of bl and cl registers, store the result in the word-size variable called
'mul_result', and store a zero in the byte-size variable called 'error'.

If 'flag' contains the ASCII code for a 'D' it should divide the contents of 
si register by the contents of ch register, store the integer part of the
quotient in the byte-size variable called 'div_result', and store a 0 in
'error'.

If 'flag' contains anything else, it should store the ASCII code for an 'E'
in 'error'.


7. Write a C language program that will compute the value of either the expression
a * 2^n  or the expression  a/(2^n), where a and n are positive integers entered 
by the user. The former should be computed if a is greater than n; the latter if 
a is greater than n. In either case, the result should be output to the screen. If 
a and n are equal nothing should be computed.  The following are sample program 
runs (underlined text is entered by the user):

Enter two integers:
56 3
56 divided by 2 to the power 3 is 7

Enter two integers:
7 10
7 times 2 to the power 10 is 7168

(Hint: use integer arithmetic and bit shifting.)



8. Write a C language program that will prompt the user to enter a two-digit 
hexadecimal integer, determine whether it is the ASCII code for a hexadecimal 
digit, and,if so, output that digit to the screen. If the integer entered is 
not the ASCII code for a hexadecimal digit, the program should display the word 
"ERROR" on the screen.The following is what should be observed on the screen 
during a couple of runs of the program (underlined text is entered by the user): 

Enter a two-digit number
42
The digit is B

Enter a two-digit number
37
The digit is 7

Enter a two-digit number
1F
ERROR

Enter a two-digit number
99
ERROR