EE 2361 - Introduction to Microcontrollers
Summer Term, 2005
Homework Assignment 2
Due: Tuesday, July 5

  1. Suppose that the contents of accumulator A are $CD. Give the contents of accumulator A and the values of the N, Z, V and C bits of the condition code register after the following instruction is executed:
    adda #$35


  2. Suppose that the contents of accumulator A are $CD and the contents of accumulator B are $8A. Give the contents of accumulators A and B and the values of the N, Z, V and C bits of the condition code register after the following instruction is executed:
    aba


  3. Suppose that the contents of memory starting at address $0030 are the following sequence of bytes: $53, $FA, $E3, $95. Explain what each step of the following program does and also give a simple one-sentence explanation of the overall purpose of the program. (You do not have to give the condition code register values after each instruction unless it has a bearing on the outcome of the program.)

    ldaa $31
    adda $33
    staa $35
    ldaa $30
    adca $32
    staa $34

  4. Re-write the previous program using a sequence of only 3 instructions involving accumulator D such that it has the same overall purpose as the program in the previous problem.


  5. Suppose that the contents of accumulator A are $00 and the contents of memory location DATA are $B0. The instruction cmpa DATA is executed, followed by one of the following types of conditional branch instruction. For each type of conditional branch instruction given below, indicate by "yes" or "no" if the branch will be taken:

    1. bge
    2. ble
    3. bgt
    4. blt
    5. beq
    6. bne
    7. bhs
    8. bls
    9. bhi
    10. blo

  6. Consider the following sequence of instructions:

    ldaa #$A0
    ldab #$14
    mul
    
    1. Assuming this represents an integer multiplication, give the decimal values of each of the operands and calculate the decimal value of the product.


    2. What are the contents of accumulators A and B and the value of the C bit in the CCR after the mul instruction has been executed?


    3. Assuming that this represents fractional multiplication, give the decimal values of each of the operands and give the decimal value of the product.


    4. Show that your answers to parts (b) and (c) are consistent with each other by interpreting the contents of accumulators A and B as a fractional value.


    5. Give the decimal value of the 8-bit fractional approximation of the 16-bit fractional product if only the contents of accumulator A are kept. (This represents truncation of the 16-bit fractional result to 8 bits.)


    6. Now suppose that the additional instruction adca #$00 is executed. Give the contents of accumulator A (in both hex and decimal formats) after this instruction has been executed. (This represents rounding of the 16-bit fractional result to 8 bits.)


    7. Calculate (in decimal) the absolute value of the difference between the truncated and 16-bit results, and the absolute value of the difference between the rounded and the 16-bit results. Which value (truncated or rounded) is the better approximation to the 16-bit result in this case?


  7. For the following signed division problems, (dividend/divisor) = quotient + (remainder/divisor). In all cases, the sign of the remainder is the same as the sign of the dividend. Also, the following equality is always satisfied: (divisor)*(quotient) + remainder = dividend.

    1. For each of the following four division problems (specified in decimal), give the decimal values of the quotient and the remainder: 26/7, (-26)/7, 26/(-7), (-26)/(-7).


    2. If the four divisions of part (a) are done using the idivs instruction, give the hex values in registers D and X just prior to and immediately after the execution of this instruction in each case.


  8. In unsigned fractional division using the fdiv instruction, the dividend is less than the divisor and the quotient is a fractional value with its radix point to the left of bit 15. For each of the following five division problems (specified in decimal), give the hex contents of registers D and X just prior to and immediately after the execution of this instruction in each case: 1/2, 1/4, 3/4, 1/3, 2/3.