Google

Jun 28, 2008

whether given number is palindrome or not

This is assembly language program for finding a given number is palindrome or not

Example:
3000 – AD
3001 – B5

AD = 10101101
B5 = 10110101 (D7=1; D6=0; D5=1; D4=1; D3=0; D2=1; D1=0; D0=1)

AD and B5 are palindrome

Algorithm
1. Take the 2nd value B5
2. The binary equivalent of it (10110101), is cut into bits n each bit is put in address ranging from 8001 to 8008 in the reverse order. That is, D0 is put in 8001; D1 in 8002 and so on—until D7 in 8008
3. This is done by rotating 10110101 right thro carry
4. Thus the carry values are stored into the addresses (8001 – 8008)
5. Hence we get, 8001 – 00000001
8002 – 00000000
8003 – 00000001
8004 – 00000000
8005 – 00000001
8006 – 00000001
8007 – 00000000
8008 – 00000001
6. Each of these values hafta b shifted so as to get 10000000 of 8001
00000000 of 8002
00100000 of 8003
00000000 of 8004
00001000 of 8005
00000100 of 8006
00000000 of 8007
00000001 of 8008
7. Add the values present in 8001 to 8008 n store it in the register C. Hence in register C, we have the value AD after rotating B5)
8. Get the 1st value from 3000 n store it in accumulator (register A)
9. Subtract A and C registers
10. If the numbers are palindrome, 01h gets stored in memory 4000
11. If the numbers r not palindrome, 02h is stored in memory 4001
12. end

the program

Label Mnemonics

MVI H, 08h
MVI L, 01h
MVI C, 08h
LDA 3001
rotate: RAR
JC one
JNC zero
one: MVI M, 01h
JMP next
Zero: MVI M, 00h
Next: INC L
DCR C
JNZ rotate
MVI L, 00h
Inc: INC L
MOV D, L
MOV A, L
SUI 09h
JZ fini
MOV A, M
Hey: RRC
DCR D
JZ inc
JNZ hey
Fini: MVI L, 00h
MVI C, 00h
Other: INC L
MOV A, M
MOV B, A
INC L
MOV A, M
ADD B
ADD C
MOV C, A
MOV A, L
SUI 08h
JNZ other
MVI H, 30h
MVI L, 00h
MOV A,M
SUB C
JZ palin
JNZ nopalin
Palin: MVI A, 01h
STA 4000
JMP over
Nopalin: MVI A, 02h
STA 4001
Over: HLT

You might be also interested in:

:: Assembly Language Programs to compute an expression
:: Interfacing Analog-to-Digital converter to 8086 using 8255
:: Interfacing Digital-To-Analog converter to 8086 using 8255
:: Temperature Control system using 8086