Yes, you've definitely got a problem using B like that; the counter is getting overwritten when you get the value from
data2
, and isn't saved or restored anywhere. Your options are to either push the counter onto the stack while performing the compare, then restoring it for the loop indexing, or else use a memory compare rather than loading the value at the
data2
into B. The latter is probably the better alternative.
Code:- loop:
- ldaa 1,x+ ;going through data1
- cmpa 1,y+ ; compare A directly to data2
- bne loop ; if not 0 branch back to loop
- incb ; increment B
- cmpb #100 ; check if end of array
- bne loop
Copy Code I'm not
certain
if this is right, as I don't know the processor that well, but from what I see in the instruction set, it should work.
For the pointers, are you sure you want
ldx
/
ldy
and not
leax
/
leay
? If I am not mistaken, as it is written now, what you are loading into X and Y are the values held in the locations
data1
and
data1
. If those are pointers, then that is correct; but if those are the actual arrays, as seems to be the case, then you want to load their effective addresses instead. Since you don't show the two strings, I'm not sure which is the case. |