need help on MC68HC11 L2.8

Mark44

Joined Nov 26, 2007
628
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
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
 

Thread Starter

thiensu666

Joined Sep 22, 2008
4
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
 

Mark44

Joined Nov 26, 2007
628
Rich (BB code):
          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
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.
 

Thread Starter

thiensu666

Joined Sep 22, 2008
4
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
 

Mark44

Joined Nov 26, 2007
628
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
Thiensu666,
Here's what I said earlier in this thread:
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.
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
 
Top