;******************************************************
;*                                                    *
;* TEST.ASM to test XASM68K. See p. 109 P.J.          *
;*                                                    *
;* PROGRAM TO COUNT THE NUMBER OF "1" IN A LONG WORD. *
;*                                                    *
;******************************************************
;*
;* FUNCTION REGISTERS
;* -------- ---------
;*
;* D0.B = COUNT BIT
;* D1.B = COUNT LOOP
;* D2.L = LONG WORD
;*
         ORG     $2000

         LEA.L   STACK,SP        ; INIT STACK PTR
         MOVE.L  LWORD,D2        ; D2 := (LWORD)
         BSR.S   TST0
         TRAP    #1              ; RETURN TO EUROMAK SYSTEM
         DC.W    0

TST0     MOVEM.L D0-D1,-(SP)     ; SAVE ALTERED REGISTERS
         CLR.B   D0              ; D0.B := 0 /* COUNT BIT "1" */
         MOVEQ   #31,D1          ; D1.B := 31
LOOP1    TST.L   D2              ; DO WHILE D2 <> 0
         BEQ.S   ENDPROG         ; { LABEL 8 CHARS =============== }
         BCLR.L  D1,D2           ;  IF NUMB BIT <> 0 THEN
         BEQ.S   LOOP            ;   Z := 0; NUMB BIT := 0; D0 := D0 + 1
         ADDQ.B  #1,D0           ;  ELSE
LOOP     DBRA    D1,LOOP1        ;   Z := 1; NUMB BIT := 0
ENDPROG  MOVE.B  D0,NUMB         ;  ENDIF
         MOVEM.L (SP)+,D0-D1     ; ENDDO
         RTS

LWORD    DS.L    1
NUMB     DS.W    1
         DS.L    5               ; SPACE FOR STACK
STACK    EQU     *
         END
END
