;----------------------------------------------------------------- ; EX64.ASM COUNT ONES C.P. Diduch 2001 ; ; Count the number of ones in the memory variable DATA ; and store the number in memory variable SUM. ; ; Author(s): ; Signature(s): Date: ;----------------------------------------------------------------- .ORG 0x0000 ; "variable assignments in RAM" DATA: .DS 1 ; unsigned DATA, SUM ; SUM: .DS 1 ; ; .ORG 0x8000 ; "assign the following to ROM" ; ; void main(void) { ; ; do { L0: XOR R0, R0, R0 ; SUM = 0 ; STOREM SUM, R0 ; LOADP R0, 0x0001 ; DATA = inport(0x0001) ; STOREM DATA, R0; ; XOR R7, R7, R7 ; i = 0; // Reg. var. in R7. L1: SUBL NULL, R7, 16 ; while (i < 16) { JMPNC L3 ; ; SHIFTU R0, R0, 1(NULL) ; if (Bit-i of DATA == 1) { JMPNC L2 ; LOADM R1, SUM ; SUM = SUM + 1 ; ADDL R1, R1, 1 ; STOREM SUM, R1 ; } L2: ADDL R7, R7, 1 ; i = i + 1 ; JMP L1 ; } ; L3: LOADM R3, SUM ; STOREP 0x0002, R3 ; outport(0x0002, SUM) ; JMP L0 ; }