This program will count all the 1s and 0s individualy presents in a 1 byte word. And store the result in individual places in Memory. Suppose, argument byte is stored in memory location 2050H and store the result of 1's count at 2060H memory location and 0's at 2061H
Memory Location | Hex Code | Label | Mnemonics | Comment |
3050 3051 3052 | 3A 50 20 | START: | LDA 2050H | ;Load Accumulator with the number stored at location 2050H |
3053 3054 | 06 00 | MVI B, 00H | ;Initiate 0's Counter | |
3055 3056 | 0E 00 | MVI C, 00H | ;Initiate 1's Counter | |
3057 3058 | 16 08 | MVI D, 08H | ;Initiate Bit Counter | |
3059 | 07 | LOOP: | RLC | ;Rotate Accumulator Left with Carry |
305A 305B 305C | DA 61 30 | JC ONE | ;If 1 is found count 1 | |
305D | 04 | INR B | ;If 1 is not found it must be 0. So increase 0's Counter | |
305E 305F 3060 | D2 62 30 | JNC NEXT | ;Go to next Bit | |
3061 | 0C | ONE: | INR C | ;Increase 1's Counter |
3062 | 15 | NEXT: | DCR D | ;Decrease the Bit Counter |
3063 3064 3065 | C2 59 30 | JNZ LOOP | ;If all Bits is not checked execute for next Bit | |
3066 | 79 | MOV A, C | ;Move 1's Count Result to Accumulator | |
3067 3068 3069 | 32 60 20 | STA 2060H | ;Store the Result for 1's Count | |
306A | 78 | MOV A, B | ;Move 0's Count Result to Accumulator | |
306B 306C 306D | 32 61 20 | STA 2061H | ;Store the Result for 0's Count | |
306E | 76 | HLT | ;End of the Program |
- Count 1s from the Byte
- Store the Result for 1s count
- Deduce this result from 8
- Store the Result for 0s count (what is work out by deduction)
Comments