Palindrome Program Using Assembly Language Basic Concept

Today we are going to make an program which will show that number is Palindrome or not using Assembly Language for Atmega16.Here is our question.

Write a code that detects whether a number is Palindrome or not . If they are equal set the 5th bit of DDRC and PORTC registers. Otherwise set the 3rd bit of DDRC and PORTC registers. Simulate the code on Proteus.

I have divide this tutorial in three parts.

  1. Basic Concept
  2. Code + Code explanation
  3. Proteus Simulation

Basic Concept

Take Input

Lets take input from PORTD and save the result in a register R 16. So I chose input as 1111 1111.The green color is showing LSBs(Lower Nibble) and yellow is for MSBs (Higher Nibble)

Extract the Higher Nibble

We will extract higher nibble and save the results in R17

Extract the Lower Nibble

We will extract lower nibble and save the results in R18

SwapLower Nibble

Now we will swap lower nibble register R18 having LSBs. The swaping can be done simply by swap command and our register will become as in below table .Now notice that both R17 and R18 have MSBs

Separate Bits and Shift

Separate all four bits in four different registers1:- Left Shift the register three times holding the most significant bit of the four MSB’s2: Left shift 2nd MSB register having 2nd MSB.3: Right shift the third MSB register.4: Right shift three times the forth register.

Add All Registers

Now add all the register having reorder bits.R23 = R19 + R20 + R21 + R22

Compare the Reordered Bits

Now compare the reordered bits with unordered bits. For code please visit Part2


 Download Files

Let's Discuss