0

Trying to calculate the number of zero for any given array

            ORG     $8000
START       MOVEA.L #V0,A0
COUNTERT    CLR     D0
COUNTERF    CLR     D1      
RIEMP       MOVE    NELEM,D2

LOOP        CMP     #0,(A0)+
            BEQ     COUNT
            CMP     D0,D1
            BGT     UPDATEF
CKR         ADD     #-1,D2
            BEQ     STORE   
            BRA     LOOP

COUNT       ADDI    #1,D0
            BRA     LOOP

UPDATEF     MOVE    D0,D1
            CLR     D0
            BRA     CKR

STORE       MOVE    D1,LZ
FINE        JMP     FINE

            ORG     $8200
V0          DC.W    1,0,0,1,0,-3,1
V1          DC.W    0,-3,0,0,0,0,2
V2          DC.W    1,0,-1,1,0,-3,2
V3          DC.W    1,5,--1,2,4,-3,1
NELEM       DC.W    7

            ORG     $8300
LZ          DS.W    1

            END     START

But the second CMP D0,D1 doesn't activate the BGT UPDATEF to store the value of the greater counter

  • In the case of finding a 0, the code skips the count down part, and resumes at the top of the loop. After COUNT is done you probably want to go to the CMP D0,D1 instead, or maybe go to CKR at least, to keep the counter accurate. – Erik Eidt Jul 16 '20 at 17:41
  • It's not about an accourate counter, I'm using 2 register to store the temporary value and the final value but I can't MOVE D0,D1 because it doesn't jump to UPDATEF. – Savio Del Peschio Jul 16 '20 at 19:29
  • If you don't keep your counter accurate, you will run off the end of your array. Give my first comment some serious thought. – Erik Eidt Jul 16 '20 at 20:53

0 Answers0