1

The checksum is computed as the sum without carry of each byte of the array and is put in the register B. The size of the array is in register A and the array is in memory starting at the address in register X.

So far I got this program:

      ORG  $C000

      LDAA #N
      LDAB #$00
LOOP  DECA

      ADDB 0,X
      INX
      CMPA #0
      BNE  LOOP
END

I think that would do the job but I'm new with assembly and the 68HC11. Can you tell if you see something wrong? Thanks in advance.

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
user43680
  • 33
  • 6
  • 1
    Don't know that assembly, but aren't you forgetting to decrement A? Oh, never mind, you have DECA, it's not part of LOOP... :) – hyde Oct 13 '12 at 18:51
  • ok so DECA shouldn't be part of the loop? and it is an assignment. – user43680 Oct 13 '12 at 20:36
  • 1
    Your code would be more efficient if you removed the first DECA, and replaced the CMPA #0 with DECA. Of course, your code as written won't handle a zero-length array, which happens in practice. I agree with @hyde; while this computes a checksum, you should use a stronger scheme (as he suggested) in practice. Those are are lot harder to code. – Ira Baxter Oct 13 '12 at 22:07
  • thanks for your comment very helpful! If you want post it as an answer and I'll accepted. And how do I make the code to handle zero-length array? – user43680 Oct 14 '12 at 04:26

1 Answers1

1

Here is the code to handle zero-length array (will return B=0):

      LDAB #$00
      LDAA #N
      BEQ END
LOOP  ADDB 0,X
      INX
      DECA
      BNE  LOOP
END
Laurent H.
  • 6,316
  • 1
  • 18
  • 40