CS2011: Sample Final Exam

 

** answers will NOT be posted, some problems will be reviewed during the review session **

 

 

1.      (10 points) Assume that AX contains 18ADh and DX contains 0C21h. Show the contents of AX after each of the following instructions executes (do each part independently). Give your answers in hex:

 

 

a.       OR             AX, DX










b.      ROL          AX, 9

 

 

 

 

 

 

 

 

 

 

 


 

 

2.      (25 points) We want to write a recursive program to calculate a simple summation:

In this program, the value of n is passed from the main program to the procedure by being pushed on to the stack. For example, if i = 3, the result is 3 + 2 + 1.
                 
 a. Code fragments for the calling procedure and the recursive function are shown below. Fill in the missing instructions (location denoted by **) to implement the summation (sometimes more than one instruction per **!!!).

MAIN PROGRAM:

.startup
mov            ax, 3     ;n = 3
push           ax
call             sum
;answer comes back in ax (3 + 2 + 1)
nop
.exit

FUNCTION

sum            proc
                  push     bp
                                          ;** finish setting up stack frame
                                          ;** retrieve parameter
                                          ;** check termination condition

                                          ;**set up argument for recursive call

                  push     ax         ;call with (n-1)
                  call       sum      ;recursive call

                                          ;**retrieve parameter

                                          ;**calculate summation

back:          pop      bp
                  ret        2          ;important to clean up arguments!!!
sum            endp


                                               
b. Draw a picture of the stack segment at the deepest level of recursion during the execution of this program (what the stack looks like inside sum after you have pushed bp when the argument to sum is 0). Be sure to label BP, SP, and SS, as well as indicate the contents of each word on the stack.

 

 

 

 

 

 

 

 

 


3.       (15 points) Given the following truth table:

 




 

a.       Give the sum of products expression






 

b.      Given the following Karnaugh map setup, finish defining the Karnaugh map (finish labeling it as well as filling in the values for the expression) and find a simplified Boolean expression for the truth table.











4.      A half-subtractor is a circuit that computes a difference by subtracting one bit from another. Like the half-adder, it has an extra output, in this case specifying whether a 1 has been borrowed.

a. (8 points) Give the truth table for a half-subtractor

















b. (7 points) Draw a circuit diagram of the half-subtractor.

 

 


5.      (15 points) For the following questions, refer to the attached microprogramming information.

 

a.       How many microinstructions in our microprogram (on attached handout) must be executed to implement the assembly level instruction  STORE? (In your answer, include all the microinstructions involved in fetching and decoding the instruction, as well as those involved in executing the STORE instruction). For maximum partial credit, list the line numbers of the executing instructions.

 

 

 

 

 

 

 

 

 

 

b.      What would the binary microcode be for the following microinstruction? For maximum partial credit, list the value of each field as well as giving the binary.

 

TMP = MBR + 1; if N then goto 5

 


 

6.      (10 points) Here is how two different routines to add numbers a and b could be called from a C program:

res = addem1(a, b);

addem2(a, b, &res);

Both func1 and func2 are written in assembly language.

a. How would addem1 return the result to the C program? (Don’t write code, just explain how the value gets returned).










 

 

 

 

b.  Draw the stack inside addem2. Draw the direction of memory and the location of SP.


 

7.      (10 points) The table below lists the inputs applied to a clocked SR-latch over time. Fill in the last row of the table, indicating the state of the latch after each pair of inputs has been applied. (The answer given for each time unit must be either 0 or 1). 

 

time (t)       0          1          2          3          4          5          6          7          8          9

Clock         1          0          1          0          1          0          1          0          1          0

S                1          1          0          0          0          0          0          1          1          1

R                0          0          1          1          0          1          1          0          0          0

     Q(t+)