need help on MC68HC11 L2.8

Discussion in 'Homework Help' started by thiensu666, Sep 22, 2008.

  1. thiensu666

    Thread Starter New Member

    Sep 22, 2008
    4
    0
    Hello,

    I am stuck on a lab assignment problem from the book MC68HC11: An Introduction Software and Hardware Interfacing. Here's a link to the specific problem. It's problem L2.8; http://books.google.com/books?id=4Jq...um=2&ct=result
    please help me out thank all
     
  2. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    The modulus operator is your friend. For a number n that is divisible by 8, n mod 8 is zero. Write a loop that tests each of the 20 numbers in the array, and keep track of how many are such that n mod 8 is zero.

    If you show us what you've done, someone here will no doubt be able to help you.
    Mark
     
  3. thiensu666

    Thread Starter New Member

    Sep 22, 2008
    4
    0
    ORG $00
    cout FCB 20
    ORG $2000
    LDAA #0
    STAA count
    loop LDDD 0,y
    LDX #8
    IDIV
    XGDX
    STAB 32,y
    INY
    DEC count
    BNE loop
    SWI
    ORG $3000
    array FCB 8,24,32,100,4,12,108,40,60,72,96,20,16,80,200,220,164,196,204,248
    END


    this is all i got so far. how do i make it use the right number in the array divisible by 8??

    L2.8 write a program to determine how many element in an array are divisible by 8. the array has 28bit elements and store it at $D000-$D013. store the result at $20
     
  4. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    First off, it looks like you misspelled count, which you have as cout.

    You're on the right track with the IDIV instruction. The Motorola instruction set reference says that this instruction
    "Performs an unsigned integer divide of the 16-bit numerator in D
    accumulator by the 16-bit denominator in index register X and sets the
    condition codes accordingly. The quotient is placed in index register X,
    and the remainder is placed in the D accumulator. The radix point is
    assumed to be in the same place for both the numerator and the
    denominator. The radix point is to the right of bit 0 for the quotient. In the
    case of divide by zero, the quotient is set to $FFFF, and the remainder
    is indeterminate."

    As far as I can tell (you don't include any comments), your count variable keeps track of the number of array elements. You also need another variable to keep track of how many numbers are divisible by 8. This number needs to be initialized to zero, and should be incremented each time the loop finds a number that is divisible by 8.

    I can't tell what you're doing inside your loop. Again, you should add comments to make it clear to the reader. It wouldn't hurt to have a comment on every line, at least in the loop.

    You're not using the array you set up. I'm guessing that the line you have that says STAB 32, y is your attempt to store the 2nd array value.

    Each time through your loop you should do these operations:
    1. Load the value from the current position in the array into the D accumulator.
    2. Load 8 into the X register.
    3. Use IDIV on the current array element.
    4. Compare the value in the D accumulator with 0.
    5. If the value in the D accumulator is 0, add 1 to your variable that keeps track of how many numbers are divisible by 8; otherwise don't do anything. To implement this if logic, you can use a compare instruction and a branch instruction.
    6. Decrement count.
    7. Increment the register that holds the address of the array.
    8. Branch
    to the beginning of the loop unless your count variable is zero.

    That should be close to what you want.
     
  5. veritas

    Active Member

    Feb 7, 2008
    167
    0
    Remember that for a number N that is divisible by eight, (N and 00000111) will be zero
     
  6. thiensu666

    Thread Starter New Member

    Sep 22, 2008
    4
    0
    many thanks guys, if i stuck again i will ask you for help thanks again
     
  7. thiensu666

    Thread Starter New Member

    Sep 22, 2008
    4
    0
    ORG $00
    count FCB 20
    ORG $2000 ;Start address of answer
    LDY #array ;Set y to point at the array
    loop LDAB 0,Y ;Load array into accumulator B
    again CLRA ;Initiaize A to 0
    LDX #8 ;Load X with the divider #8
    IDIV ;Divide array by 8
    XGDX
    STAB 32,y ;Store the answer in memory
    CMPB #0
    INY ;Point Y to next number in array
    DEC count
    BNE loop
    exit SWI
    ORG $3000
    array FCB 8,24,32,100,4,12,108,40,60,72,96,20,16,80,200,220,164,196,204,248
    END

    please help me fill in what i miss in this program above L2.8
    thank you thank you
     
  8. veritas

    Active Member

    Feb 7, 2008
    167
    0
    Why are you storing B? Where are incrementing your count?
     
  9. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    Thiensu666,
    Here's what I said earlier in this thread:
    I don't see step 1 in your code, and I don't see any conditional logic in your code for step 4. You need to add some code that increments the counter that keeps track of how many array elements are divisible by eight. This would be in addition to the logic you have for executing your loop another time.

    In addition to the question from Veritas, why do you have a label named "again"? You don't have any branch instructions that branch to it, so what is its purpose?

    Have you tried to assemble and run your code? If it executes, the results you get can be helpful in diagnosing problems with the code.

    Hope that helps.
    Mark
     
  10. veritas

    Active Member

    Feb 7, 2008
    167
    0
    If I remember correctly, accumulator D is A concatenated with B, so the line
    LDAB 0, Y
    will load the array value into B (read D)
     
Loading...