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 Oct 13 2019, 07:32 AM
Aline Hutchinson
Hey there,
Sun Oct 13 2019, 03:53 AM
Sat Oct 12 2019, 03:48 PM
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 01:07 PM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Thu Sep 19 2019, 02:18 AM
Caryn Kover
Tue Aug 06 2019, 12:39 AM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 10:03 PM
Ismail balghmi
Wed Jul 24 2019, 06:17 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 11:43 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.
Fri Jul 12 2019, 01:25 AM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html

### Recent

ilylily07
Tue Oct 15 2019, 04:32 PM
hientran123
Tue Oct 15 2019, 02:27 AM
Sat Oct 05 2019, 02:38 PM
zexalo
Thu Oct 03 2019, 09:53 AM
thanhle12345
Thu Oct 03 2019, 07:37 AM
ramon_vsc
Fri Sep 20 2019, 04:53 PM
youssoufba
Thu Sep 19 2019, 11:57 AM
Taiphan000
Tue Sep 17 2019, 04:21 AM

#### Online

Guests: 43, Members: 0 ...

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

Members: 38097
Forum Activity
##### Posted By [email protected]
Thu Oct 17 2019, 09:30 AM
i want to scroll message more than 2 dot matrix di...
##### Posted By ExperimenterUK
Wed Oct 16 2019, 09:58 PM
What do you mean by "message scroll vertically" ?...
##### Posted By [email protected]
Wed Oct 16 2019, 07:38 AM
##### Posted By [email protected]
Wed Oct 16 2019, 07:13 AM
message scroll vertically, please share code.
##### Posted By ExperimenterUK
Wed Oct 16 2019, 01:10 AM
Which camera ?What do you want the micro to do ?
##### Posted By ilylily07
Tue Oct 15 2019, 04:43 PM
i need help.i don't know how to do it.is it possib...
##### Posted By ExperimenterUK
Sun Oct 13 2019, 06:10 PM
This code does some scrolling.You will need to fin...
##### Posted By ExperimenterUK
Sat Oct 12 2019, 10:19 PM
This code does not scroll, that will be complicate...
##### Posted By [email protected]
Sat Oct 12 2019, 06:44 AM
Sir, Please share code, i m unable to scroll messa...
##### Posted By ExperimenterUK
Sat Oct 12 2019, 02:45 AM
Okay I got it !Data is not automatically passed on...