Practice Final Exam for CS-220
ANSWER KEY

1. We wish to write a DISPLAY_IF macro that will display a character on
the screen of a PC if a certain condition on two values is satisfied. The
first value is specified in the macro's first argument, the condition in
the second argument, the second value in the third argument, and the
character to be displayed in the fourth argument. For example, the
invocation:

DISPLAY_IF    AX, G, BX, 'Z'

should display a 'Z' at the current cursor location on the screen
if the contents of AX are greater (G) than the contents of BX. The
invocation:

DISPLAY_IF    DL, E, 0, 30h

should display a zero (30h = ASCII code for a zero) if DL contains a 0
(i.e. if DL is Equal to 0).

(A) Complete the macro definition:

DISPLAY_IF    MACRO    OP1, OP2, CONDITION, ASC
;Your code goes here
              LOCAL        DISPLAY, DONE
              CMP          OP1,OP2
              J&CONDITION  DISPLAY
              JMP          DONE
DISPLAY:      MOV          AH,2
              MOV          DL,ASC
              INT          21H                
DONE: 
              ENDM


(B) Expand the following invocation of the macro:

DISPLAY_IF   SI, X, LE, AL
1            CMP    SI,X
1            JLE    ??0000
1            JMP    ??0001
1 ??0000:    MOV    AH,2
1            MOV    DL,AL
1            INT    21H
1 ??0001:              


2. The two-module ADDX program whose listings are given on the "Sample
Programs" Web page is assembled and linked into a single executable.
Prior to execution of the push a instruction, the registers are as shown
below:

AX=2D88  BX=0000  CX=0052  DX=0000  SP=0010  BP=0000  SI=0000  DI=0000
DS=2D88  ES=2D77  SS=2D87  CS=2D89  IP=0005   NV UP EI PL NZ NA PO NC

(A) What is the physical address (5-digit hex number) of the variable b?
    offset = 0002          
    base = DS = 2D88h 
    So Address = 2D880h + 0002 = 2D882h

(B) What is the physical address of the push ax instruction?
    offset = 0010h
    base = CS = 2D89h
    So address = 2D890h + 0010h = 2D8A0h

(C) The following tables represent the stack and the data segments
immediately before the instruction pop bp (in the ADDXSUB module) is
executed. Fill in both tables with the values that would be stored at
that moment. (In the stack table, each entry is a word, while in the data
table, each entry is a byte.)

 STACK SEGMENT               DATA SEGMENT
offset contents            offset contents
----------------           ---------------
  0    ****                   0    05
----------------           ---------------
  2    ****                   1    00
----------------           ---------------
  4    0000 (BP)              2    03
----------------           ---------------
  6    0016 (IP)              3    00
----------------           ---------------
  8    2D89 (CS)              4    08
----------------           ---------------
  A    0004 (offset sum)      5    00
----------------           ---------------
  C    0003 (b)
----------------
  E    0005 (a)
----------------

  **** = not known

3. The following assembly language program has been assembled and loaded
into the simple computer we discussed during the last week of class.

Machine Language      Assembly Language
-------------------------------------------
Address Contents
-------------------------------------------
  0A                         ORG     10
------  --------
  0A      014         X      DW      20
------  --------
  0B      00F         Y      DW      15
------  --------
  00                         ORG     0
------  --------
  00      10A                LDA     X
------  --------
  01      5**                MBA
------  --------
  02      4**                SUB
------  --------
  03      706         BBB:   JN      AAA
------  --------
  04      4**                SUB
------  --------
  05      603                JMP     BBB
------  --------
  06      8**         AAA:   HLT
------  --------
                      END

  * = "don't care" hex digit

Fill the blanks in the Address and Contents columns with the values they
would have after the program is translated to machine language. The
addresses should be expressed as two-digit hex numbers, and the contents
as 3-digit hex numbers. (Each DW declaration allocates one "word" of
memory on this machine, which, you will recall, is a single 12-bit long
number. All addresses are to be expressed as "word" addresses. Each
instruction is also one "word" long.)

What will be the value stored in the ACC register when the program stops
execution?
           -20 = -14h = -000000010100b = 111111101100b (2's complement)
                      = FECh 

IN ORDER TO PREPARE FOR THE REST OF THE REAL EXAM, YOU SHOULD CAREFULLY
REVIEW THE SECOND SET OF NOTES FROM THE WEB PAGES--"Week 2: Hardwired and 
MicroprogramedComputer Control Units". MAKE SURE YOU UNDERSTAND HOW THE 
VARIOUS TABLES AND LOGIC EQUATIONS WERE OBTAINED AND HOW THE CIRCUITS 
WORK. OF PARTICULAR IMPORTANCE IS THE ORGANIZATION OF THE HARDWIRED 
INSTRUCTION DECODER AND CONTROL MATRIX.

ALSO BE SURE YOU UNDERSTAND HOW DISK I/O WORKS.