delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

      swi  ; end of program
My problem here is that I have I am sure I dont use the accumulator B well .
I used it for initialization and to get the data through data2.
Can please someone suggest me how to handle this problem?
Thank you
B


Hi,
I have a problem this question.
count the number of values in array data1 that equal the corresponding value in the array data2. both arrays have length 100.
Code:
  1. ; initialization of pointers
  2.    ldx   data1
  3.    ldy   data2
  4.    ldab  count  ;initialize counter
  5. loop:
  6.       ldaa  1,x+   ;going through data1
  7.       ldab   1,y+   ; going through data2
  8.       CBA           ; compare A-B
  9.       bne    loop  ; if not 0 branch back  to loop
  10.       inb            ; increment B
  11.       cmpb #100   ; check if end of array
  12.       bne    loop
  13.       swi  ; end of program
Copy Code
My problem here is that I have I am sure I dont use the accumulator B well .
I used it for initialization and to get the data through data2.
Can please someone suggest me how to handle this problem?
Thank you
B

TOP

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:
  1. loop:
  2.       ldaa  1,x+   ;going through data1
  3.       cmpa 1,y+  ; compare A directly to data2
  4.       bne    loop  ; if not 0 branch back  to loop
  5.       incb            ; increment B
  6.       cmpb #100   ; check if end of array
  7.       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.

TOP

Thank you Schol-R-LEA,
I believe it should work too. I was not aware that I can use the indexed addressing with cmpa instruction.
You are right for
Code:
  1. ldx   data1
  2. ldy   data2
Copy Code
It should be:
Code:
  1. ldx   [b]#[/b]data1
  2. ldy   [b]#[/b]data2
Copy Code
This is how we usually initialize pointers in the course.
Thank you again
B

TOP


Originally Posted by brad sue
I was not aware that I can use the indexed addressing with cmpa instruction.
To be fair, that's the part I wasn't certain about, though if I am reading the documentation correctly, you can; like most CPUs with a tightly limited register file, the 6800 series (which the 68HCS12 is a descendant of - not, as someone recently claimed, the 68000, which is a completely different design) has a lot of memory-direct operations. Otherwise, you'd need to push B, load the test values and do the comparison, thern pop B for the loop. Neadless to say, you really would rather avoid that.



      swi  ; end of program
My problem here is that I have I am sure I dont use the accumulator B well .
I used it for initialization and to get the data through data2.
Can please someone suggest me how to handle this problem?
Thank you
B

TOP

Back Forum