8085 program to check whether the given 16 bit number is palindrome or not
Problem – Write an assembly language program to check whether the given 16 bit number is palindrome or not. If number is palindrome then store 01 at memory location 3050 otherwise store FF at memory location 3050.
Note – A palindrome number is a number that remains the same when its digits are reversed.
Assume that 16 bit number, to check for palindrome is stored at memory location 2050.
Examples –
Algorithm –
- Load contents of memory location 2050 in register L and contents of memory location 2051 in register H
- Move contents of L in accumulator A
- Reverse the contents of A by executing RLC instruction 4 times
- Move the contents of A in L
- Move the contents of H in A
- Reverse the contents of A by executing RLC instruction 4 times
- Move the contents of L in H
- Move the contents of A in L
- Store the content of L in memory location 2070 and contents of H in memory location 2071
- Load the content of memory location 2050 in A
- Move the content of A in register B
- Load the content of memory location 2070 in A
- Compare content of A and B. If the content is not same then store FF in A and store it in memory location 3050
- If contents of A and B are same, then Load the content of memory location 2051 in A
- Move the content of A in B
- Load the content of memory location 2071 in A
- Compare content of A and B. If the content is not same then store FF in A and store it in memory location 3050
- If contents of A and B are same, then store 01 in A and store it in memory location 3050
Program –
MEMORY ADDRESS | MNEMONICS | COMMENT |
---|---|---|
2000 | LHLD 2050 | L <- M[2050], H <- M[2051] |
2003 | MOV A, L | A <- L |
2004 | RLC | Rotate accumulator content left by 1 bit without carry |
2005 | RLC | Rotate accumulator content left by 1 bit without carry |
2006 | RLC | Rotate accumulator content left by 1 bit without carry |
2007 | RLC | Rotate accumulator content left by 1 bit without carry |
2008 | MOV L, A | L <- A |
2009 | MOV A, H | A <- H |
200A | RLC | Rotate accumulator content left by 1 bit without carry |
200B | RLC | Rotate accumulator content left by 1 bit without carry |
200C | RLC | Rotate accumulator content left by 1 bit without carry |
200D | RLC | Rotate accumulator content left by 1 bit without carry |
200E | MOV H, L | H <- L |
200F | MOV L, A | L <- A |
2010 | SHLD 2070 | M[2070] <- L, M[2071] <- H |
2013 | LDA 2050 | A <- M[2050] |
2016 | MOV B, A | B <- A |
2017 | LDA 2070 | A <- M[2070] |
201A | CMP B | A – B |
201B | JZ 2024 | Jump if ZF = 0 |
201E | MVI A, FF | A <- 01 |
2020 | STA 3050 | M[3050] <- A |
2023 | HLT | END |
2024 | LDA 2051 | A <- M[2051] |
2027 | MOV B, A | B <- A |
2028 | LDA 2071 | A <- M[2071] |
202B | CMP B | A – B |
202C | JZ 2035 | Jump if ZF = 0 |
202F | MVI A, FF | A <- FF |
2031 | STA 3050 | M[3050] <- A |
2034 | HLT | END |
2035 | MVI A, 01 | A <- 01 |
2037 | STA 3050 | M[3050] <- A |
203A | HLT | END |
Explanation – Registers A, H, L, B are used for general purpose.
- LHLD 2050: loads contents of memory location 2050 in L and 2051 in H.
- MOV A, L: moves content of L in A.
- RLC: shift the content of A left by one bit without carry. Repeat the current instruction 4 times so that contents of A get reversed.
- MOV L, A: moves the content of A in L.
- MOV A, H: moves the content of H in A.
- RLC: shift the content of A left by one bit without carry. Repeat the current instruction 4 times so that contents of A get reversed.
- MOV H, L: moves the content of L in H.
- MOV L, A: moves the content of A in L.
- SHLD 2070: stores the content of L in 2070 and H in 2071.
- LDA 2050: load the content of memory location 2050 in A.
- MOV B, A: moves the content of A in B.
- CMP B: compares the content of A and B. It set the zero flag if content is same otherwise reset.
- JZ 2024: jump to memory location 2024 if ZF = 1.
- MVI A, FF: store FF in A.
- STA 3050: store content of A in 3050.
- HLT: stops executing the program and halts any further execution.
- LDA 2051: load the content of memory location 2050 in A.
- MOV B, A: moves the content of A in B.
- LDA 2071: load the content of memory location 2071 in A.
- CMP B: compares the content of A and B. It set the zero flag if content is same otherwise reset.
- JZ 2035: jump to memory location 2035 if ZF = 1.
- MVI A, FF: store FF in A.
- STA 3050: store content of A in 3050.
- HLT: stops executing the program and halts any further execution.
- MVI A, 01: store 01 in A.
- STA 3050: store content of A in 3050.
- HLT: stops executing the program and halts any further execution.
Please Login to comment...