In this program we will see how to count number of odd numbers in a block of elements.
Write 8085 Assembly language program to count number of odd numbers in a block of data, where the block size is 10D. The block is starting from location 8000H.
The Odd Even checking is very simple. we can determine one number is odd or even by checking only the LSb. When LSb is 1, the number is odd, otherwise it is even. In this program we are taking a number from memory and then ANDing 01H with it. if the result is nonzero, then the number is odd, otherwise it is even.
Address | Data |
---|---|
. . . | . . . |
8000 | DA |
8001 | 53 |
8002 | 26 |
8003 | 41 |
8004 | 17 |
8005 | AC |
8006 | 78 |
8007 | D8 |
8008 | 9C |
8009 | 3F |
. . . | . . . |
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 21, 00, 80 | | LXI H,8000H | Point to the starting byte |
F003 | 0E, 0A | | MVI C,0AH | Initialize count to 0AH |
F005 | 06, 00 | | MVI B, 00H | Clear B register |
F007 | 7E | LOOP | MOV A,M | Load the item from memory |
F008 | E6, 01 | | ANI 01H | AND A with 01H |
F00A | CA, 0E, F0 | | JZ SKIP | If Z = 0, jump to skip |
F00D | 04 | | INR B | Increase B by 1 |
F00E | 23 | SKIP | INX H | Point to next location |
F00F | 0D | | DCR C | Decrease C by 1 |
F010 | C2, 07, F0 | | JNZ LOOP | if Z = 0, go to loop |
F013 | 78 | | MOV A,B | Load the count to A |
F014 | 32, 50, 80 | | STA 8050H | Store the result at 8050H |
F017 | 76 | | HLT | Terminate the program |
Address | Data |
---|---|
. . . | . . . |
8050 | 04 |
. . . | . . . |