Discussion in "8051 Discussion Forum" started by    Rizz    Jan 25, 2019.
Fri Jan 25 2019, 06:31 PM
I have written a code to check if a number is a palindrome or not.
But i'm not sure if its valid in all the cases
Can someone help me with possible test cases where this code would fail.

```org 0000h
sjmp start
org 0030h
start:
mov a,#0a5h  //a5h in bin 10100101,its a palindrome,same when read backwards and forward
mov b,a
swap a         //changing no. to 5ah
mov 40h,a            //moving the result to some random address
swap a           //swapping the nibbles
cjne a,40h,exit     //now if value at 40h is equal to the value after swapping its nibble,then its a palindrome.basically proving that addition product's upper nibble == lower nibbles.
//not sure if the logic is exactly correct.
setb 30h    //sets bit high if the no. is a palindrome
exit:nop
end                    //this code works on other no.'s like 81h etc also.
```

Thank you

[ Edited Sat Jan 26 2019, 06:42 AM ]
Sat Jan 26 2019, 02:30 AM
What is your definition of a Palindrome ?
The ones I have seen are multi bytes long.
Can you comment your code to explain what every line does.
Sat Jan 26 2019, 06:43 AM
@ExperimenterUK I have updated the post with more comments . Hope its clearer now.
Sat Jan 26 2019, 07:19 PM
Yes that helps a lot.
At first sight I can't see that addition is a good test.
I would go for a loop that tests each bit like this.

Make a copy of the test byte in A and B

Is top bit of A same as bottom bit of B ?
if no, then not a palindrome, exit loop
Rotate A left, rotate B right.
repeat 4 times.
If you reach the end, it is a palindrome.

[ Edited Sun Jan 27 2019, 06:39 AM ]

### Information

#### Conversation

Sun Aug 18 2019, 11:51 PM
latamdateall
swimming
Sun Aug 18 2019, 10:25 PM
Melinda Mendenhall
aaaaaaaaaaaaaaa
Sun Aug 18 2019, 03:39 AM
charmdatescamreviewslpb
writing
Sun Aug 18 2019, 02:20 AM
charmdatehks
cooking
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html
Thu Jul 11 2019, 07:44 PM
@praveen123. Can you give a link to the project ?

### Recent

jualanled
Sat Aug 17 2019, 03:41 AM
Wed Aug 07 2019, 10:35 AM
hieu16005
Sat Aug 03 2019, 01:16 PM
Pra
Mon Jul 29 2019, 07:39 AM
manu8193
Wed Jul 24 2019, 04:44 AM
3AAPC
Sun Jul 21 2019, 12:41 AM
rpels7707
Fri Jul 19 2019, 11:31 AM
ameya123
Fri Jul 19 2019, 07:36 AM

#### Online

Guests: 41, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38086

#### Trending Topics

Forum Activity
##### Posted By [email protected]
Wed Aug 07 2019, 10:38 AM
I am trying to execute USSD codes through my GSM m...
##### Posted By ExperimenterUK
Sun Jul 28 2019, 08:55 PM
An LM339 may not be fast enough for reliable SPI ...
##### Posted By sakibnaz
Sun Jul 28 2019, 06:40 AM
Hi All.I need to connect my MCU with an external S...
##### Posted By ExperimenterUK
Wed Jul 24 2019, 10:42 PM
Your unit is communicating, so I assume the GPS si...
##### Posted By ExperimenterUK
Wed Jul 24 2019, 10:32 PM
##### Posted By manu8193
Wed Jul 24 2019, 04:57 AM
any one tell me the explaination and 'c' code for ...
##### Posted By 3AAPC
Sun Jul 21 2019, 12:51 AM
##### Posted By 3AAPC
Sun Jul 21 2019, 12:47 AM
With the GPS antenna in the outdoors, I use the ub...
##### Posted By ameya123
Fri Jul 19 2019, 07:42 AM
Hello,Please share 8051 Assembly language code for...
##### Posted By figureyang
Fri Jul 05 2019, 04:37 AM