Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Split two digit number in separate digits

Status
Not open for further replies.

Ooopscrash

Newbie level 3
Joined
May 10, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
18
Hi, how can I split a two digit number in separate digits in assembly?
For example, i got 00010111 which is 23, how can i split this numer to get 00000010 and 00000011? (2 and 3)
I'm using pic16f877a
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Convert from Decimal to BCD and extract the LSB 4 bits and MSB 4 bits.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,859
Helped
4,854
Reputation
9,726
Reaction score
4,640
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
126,485
You are asking for an 8-bit binary number to be converted to two 4-bit BCD numbers.

Probably the easiest way is to count how many times you can subtract 0x0A (10 in decimal) from your number, this gives the first digit of your answer. The remainder after subtraction is the second digit of your answer.

Brian.
 

Ooopscrash

Newbie level 3
Joined
May 10, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
18
well, because i'm a newbie i was hoping for some piece of code :D
I know the theoretical things, my problem is at writing asm code.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top