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
Sun Apr 14 2019, 10:52 PM
@hassan malik post your problem in the "General help Guidance and Discussion" forum
Sun Apr 14 2019, 05:06 PM
RAJESH MAPARi
please send me code to interface atmega32 with 24c1024 serial eeprom
Sun Apr 14 2019, 01:33 PM
hassan malik
hello sir i installed proteus 7.8 professional on window 7 ultimate and window 10 but there would be same errors onn both windows. the error is bad license key.please any one help me
Sun Apr 14 2019, 01:32 PM
hassan malik
hello sir i installed proteus 7.8 professional on window 7 ultimate and window 10 but there would be same errors onn both windows. the error is bad license key.
ExperimenterUK
Sat Apr 06 2019, 05:59 PM
@deshrar. Please post your question in 8051 forum
Sat Apr 06 2019, 07:43 AM
deshraj
hallo mam.. i have downloded gsm notice board code its running fine on lcd but how so send msg to the module . i mean format of password and msg.. thank you
kevinharsha
Wed Apr 03 2019, 04:38 PM
Can i see the circuit diagram for the music tone library 8051 project?
ExperimenterUK
Wed Apr 03 2019, 02:45 AM
@Prudhvi. Please post your request in 8051 forum
Tue Apr 02 2019, 01:02 AM
Prudhvi reddy
Can you please help me writing code for gsm to send a particular SMS after pressing a key in 4×4 keypad ..in 8051
Thu Mar 28 2019, 02:11 PM
Jamie Butler
Hi,

Downloads

Comments

gigyani
Thu Apr 18 2019, 01:43 AM
Deekshaaan
Wed Apr 17 2019, 03:02 PM
popli
Mon Apr 08 2019, 02:31 AM
kevinharsha
Wed Apr 03 2019, 04:33 PM
WWSIERT
Wed Apr 03 2019, 01:02 PM
Ausonagara
Mon Apr 01 2019, 10:42 AM
tutu10
Tue Mar 12 2019, 07:11 AM
Raj243
Fri Mar 08 2019, 02:08 AM

Online

Guests: 107, Members: 0 ...

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

Members: 38058
Newest member: gigyani
Forum Activity
gigyani Avatar
Posted By gigyani
Thu Apr 18 2019, 10:09 PM
I'm using keil uvision5. attached is the rar file ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Apr 18 2019, 04:58 PM
Please zip your full code and post it.Which assemb...
gigyani Avatar
Posted By gigyani
Thu Apr 18 2019, 02:01 AM
STATREAD:MOV A, #WTCMD ;LOAD WRITE CO...
Deekshaaan Avatar
Posted By Deekshaaan
Wed Apr 17 2019, 04:26 PM
hello i downloaded the frequency counter project f...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Apr 16 2019, 12:23 AM
1) Can you explain what is the use of the p-n-p tr...
kevinharsha Avatar
Posted By kevinharsha
Sun Apr 14 2019, 06:26 PM
Hey! Thanks for the help! The circuit worked well ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Apr 05 2019, 10:05 PM
Here is a version for the 8051.Make sure you add d...
kevinharsha Avatar
Posted By kevinharsha
Thu Apr 04 2019, 05:05 PM
http://www.8051projects.net/download-d231-musical-...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Apr 03 2019, 10:25 PM
HiAjay is very busy with business right now so may...
kevinharsha Avatar
Posted By kevinharsha
Wed Apr 03 2019, 04:48 PM
I had a couple of questions :-1) Can you upload a ...