*********
* Program COUNT_1S (6811)
*
* Reads switchs.  Outputs the number of switches at logic one on
* discrete LEDs.
*
* Uses shift technique to count number of ones.  Illustrates a use
* of the carry flag.
*
* P. H. Anderson, 12 Sept 91; Checked 12 Sept 91; 15 Jan 93
**********

PSCT    EQU $C000
DSCT    EQU $D000
IDSCT	EQU $D300

REG_BASE	EQU $1000

PORTB   EQU $04
PORTC   EQU $03
DDRC    EQU $07

        ORG PSCT

	LDY #REG_BASE
        CLR DDRC,Y      * portc configured as input
TOP
        CLR NUM_ONES    * zero number of ones

        LDAA #$08       * 8 bits to examine
        STAA BITS_LEFT

        LDAA PORTC,Y    * get the switches

L1      LSRA
        BCC AROUND

        INC NUM_ONES    * bit was a one

AROUND  DEC BITS_LEFT
        BNE L1

* at this point all 8 bits have been examined.

        LDAA NUM_ONES   * output the number of ones
        STAA PORTB,Y    * to discrete LEDs
        BRA TOP

        ORG DSCT

NUM_ONES  RMB 1
BITS_LEFT RMB 1

