Discussion in "8051 Discussion Forum" started by    Rizz    Jan 25, 2019.
Fri Jan 25 2019, 06:31 PM
#1
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
		add a,b           //adding 5ah and a5h   5ah+a5h=bin(1111 1111)
		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
#2
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
#3
@ExperimenterUK I have updated the post with more comments . Hope its clearer now.
Sat Jan 26 2019, 07:19 PM
#4
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 ]

Get Social

Information

Powered by e107 Forum System

Conversation

ExperimenterUK
Mon Jan 07 2019, 03:31 AM
@REVOCATUS please post in the AVR forum
Mon Dec 24 2018, 09:25 AM
REVOCATUS MATEMU
sorry I mean referee boards for player substitution
Mon Dec 24 2018, 09:24 AM
REVOCATUS MATEMU
hi am.looking how to build referee by using Atmega 328 and its codes
Sat Dec 15 2018, 01:45 PM
Arslan ayoub
Hii ,, can I get the simulation of numeric keypad lock on proteus
ExperimenterUK
Mon Dec 03 2018, 05:17 PM
Please post questions in the forum. The chat box is for chat
Mon Dec 03 2018, 06:43 AM
help!me!
help! I don't understand busy flag!
Sun Dec 02 2018, 08:01 PM
ile
hello
Mon Nov 12 2018, 05:58 AM
Pavan_user
i have seen your replica of I2C programming using AT89C51 but i am unable to understand the "ack_bit" variable usage ...looks like it is always 1...can you elaborate how acknowledgment is working....
bgk3678
Tue Nov 06 2018, 02:36 PM
kindly any one give solution for my problem
ExperimenterUK
Mon Nov 05 2018, 09:48 PM
Pins high is the normal state. You need a program to set them low

Downloads

Comments

the_Doker
Thu Feb 14 2019, 02:21 PM
XanZes
Thu Feb 14 2019, 01:02 AM
dominicchiori
Wed Feb 06 2019, 01:41 AM
tandong
Sun Jan 27 2019, 01:38 PM
Rizz
Fri Jan 25 2019, 06:24 PM
Kheirodin
Tue Jan 22 2019, 11:54 PM
garfield0929
Sun Jan 20 2019, 12:48 AM
servprov
Thu Jan 17 2019, 06:44 AM

Online

Guests: 46, Members: 0 ...

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

Members: 38045
Newest member: the_Doker
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Jan 26 2019, 07:19 PM
Yes that helps a lot.At first sight I can't see th...
Rizz Avatar
Posted By Rizz
Sat Jan 26 2019, 06:43 AM
@ExperimenterUK I have updated the post with more ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Jan 26 2019, 02:30 AM
What is your definition of a Palindrome ?The ones ...
Rizz Avatar
Posted By Rizz
Fri Jan 25 2019, 06:31 PM
I have written a code to check if a number is a pa...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Jan 06 2019, 10:37 PM
Which 8051 chip are you using ?
SONACHAI1234 Avatar
Posted By SONACHAI1234
Sun Jan 06 2019, 08:21 AM
Hi,By mistakenly i burn rx program in my 8051 micr...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Dec 19 2018, 06:27 PM
Nobody knows?sifirsekizThe problem is that you are...
sifirsekiz Avatar
Posted By sifirsekiz
Wed Dec 19 2018, 12:15 PM
sifirsekiz Avatar
Posted By sifirsekiz
Sun Dec 16 2018, 11:13 PM
Guys pleaseeeee :((
sifirsekiz Avatar
Posted By sifirsekiz
Sat Dec 15 2018, 07:09 PM
HiThe pulse-sensor-amped has an analogue output.Th...