Saturday, 16 March 2013

A µP 8085 ALP to Sort out even and odd number

Algorithm:
1. Store the input data bytes in consecutive memory locations.
2. Fetch each data byte and check it D0 bit.
3. If D0 bit=0 then even, else odd.
4. Store odd in  memory locations. Store even in some other consecutive memory location.

I/P 6 data byte from 9500H, store odd from 8600H and even from 8700H.

                       LXI H,9500H
                  LXI B,8600H
                  LXI D,8700H
                  MVI A,06H
COUNTR   STA 9100H
                  MOV A,M
                  ANI 01H
                  JNZ CARRY
                  MOV A,M
                  STAX B
                  INX B 
                  JMP JUMP
CARRY      MOV A,M
                  STAX D
                  INX D
JUMP         LDA 9100H
                  DCR A
                  INX H
                  JNZ COUNTR
                  RST 1 

2 comments: