Was given the following code in class and am supposed describe what each line means in comments to the right. Is this correct?
MOVE.B #20,D0 //Move 20 into D0
MOVEA.L #$1000,A0 //Move the contents of address 1000 into A0
CLR.B D1 //Set D1 to 0
Again CMP.B (A0)+,D2 //Compare A0 to D2, then increment A0 by 1
BNE NEXT //If A0 and D2 are not equal, go to NEXT, otherwise continue
ADD.B #1,D1 //Add 1 to D1
NEXT SUB.B #1,D0 //Subtract 1 from D0
BNE Again //Branch to AGAIN if contents of A0 is not equal to D2
No, it's not correct. At the very least, this:
Again CMP.B (A0)+,D2 //Compare A0 to D2, then increment A0 by 1
...is not comparing the content of A0 to anything. It's comparing a byte at the address contained in A0 to a byte in D2 (then incrementing A0 to point to the next address).
If I'm not mistaken, in these lines:
NEXT SUB.B #1,D0 //Subtract 1 from D0
BNE Again //Branch to AGAIN if contents of A0 is not equal to D2
The zero-flag should be set/cleared based on the result of the immediately preceding sub.b
, so it's continuing for 0x20 iterations (because D0 was loaded with 0x20 in the first line).