Truncated match.
PICList
Thread
'But swapping etc'
1998\01\15@154311
by
Philip Martin
Hi all,
Can anybody help explain to me the finer points of bit swapping, masking
and converting.
That is, I know how to use the swapf command and to mask the msb or lsb,
what I cant work out is how to convert the result ie:
A register (atemp) contains the number 87, what I want to end up with is
a register (btemp) containing 8
a register (ctemp) containing 7
OK, so there the 7 is easy, but what if the starting number was
something like 32, 64 or another number where all the bits are in the
msb.
TIA,

Philip Martin 
Royal Quays If at first you don't succeed, try again. Then quit:
North Shields. no use being a damn fool about it !
PADI AOW+ W.C. Fields
email spam_OUTphilipTakeThisOuTphilmart.demon.co.uk
1998\01\15@170349
by
Andrew Warren
Philip Martin <.....PICLISTKILLspam@spam@MITVMA.MIT.EDU> wrote:
> A register (atemp) contains the number 87, what I want to end up
> with is:
>
> a register (btemp) containing 8
> a register (ctemp) containing 7
Philip:
If that "87" is 87 HEXADECIMAL, it's easy:
SWAPF ATEMP,W
ANDLW 00001111B
MOVWF BTEMP
MOVF ATEMP,W
ANDLW 00001111B
MOVWF CTEMP
If it's a decimal number, on the other hand, you need to do something
like this:
CLRF BTEMP
MOVF ATEMP,W
MOVWF CTEMP
DIVBY10 MOVLW 10
SUBWF CTEMP,W
BNC DONE
MOVWF CTEMP
INCF BTEMP
GOTO DIVBY10
DONE ....
Andy
=== Andrew Warren  fastfwdKILLspamix.netcom.com
=== Fast Forward Engineering  Vista, California
=== http://www.geocities.com/SiliconValley/2499
1998\01\15@175053
by
Carlos Betancourt

> A register (atemp) contains the number 87, what I want to end up with is
> a register (btemp) containing 8
> a register (ctemp) containing 7
>
> OK, so there the 7 is easy, but what if the starting number was
> something like 32, 64 or another number where all the bits are in the
> msb.
>
> TIA,
>
> 
> Philip Martin

> email .....philipKILLspam.....philmart.demon.co.uk
Hi, List mates. I'm new in the pic world and this is my first post to the
list. By now, I've been reading manuals and simulating code in my PC so
I've given some first steps.
I think that the solution to this problem is a BINARY to BCD conversion
routine. In application note AN544 you will find the code you need for
8bit and 16bit numbers. Notice that this routines are written for the
17c42. They are sort of long so I won't include them within this post.
Surf Microchip's site (http://www.microchip.com). You'll find AN544 at:
http://www.microchip.com/10/Appnote/PIC17CXX.htm
BCD ARITHMETIC ROUTINES start on page 37.
I Hope it helps.
Carlos Betancourt
CETIUNET
Venezuela
1998\01\16@012153
by
Mike Keitz

On Thu, 15 Jan 1998 19:39:02 +0000 Philip Martin
<EraseMEphilipspam_OUTTakeThisOuTPHILMART.DEMON.CO.UK> writes:
>Hi all,
>A register (atemp) contains the number 87, what I want to end up with
>is
>a register (btemp) containing 8
>a register (ctemp) containing 7
This is straightforward, do something like:
swapf atemp,w ;Move high 4 bits of atemp to
low 4 of W
andlw b'00001111' ;Keep only low bits
movwf btemp
movfw atemp ;Get copy of atemp
andlw b'00001111' ;Keep only low bits
movwf ctemp ;Result to ctemp
This is the simple beginner's example to do what you described. Various
'trick' methods are also possible, but not really needed in this simple
case.
>
>OK, so there the 7 is easy, but what if the starting number was
>something like 32, 64 or another number where all the bits are in the
>msb.
You are talking about splitting HEX 87 into 8 and 7? If not, then the
process (for example to convert 64 (HEX 40) into 6 and 4) is known as
binary to decimal conversion. For a single byte, repeatedly subtracting
10 until the remainder (one's digit) is less than 10 is practicable. For
larger numbers, more complex (but oftendescribed) methods are necessary.
1998\01\16@053648
by
wilson
Phillip,
This list is for discussing PIC microcontrollers. If you
are interested in swapping your butt or any other bodily
part, then I suggest that you post to one of the fetish
newsgroups ...
<grin>
Internet communications are not secure and therefore the Barclays Group does
not accept legal responsibility for the contents of this message.
1998\01\16@161615
by
Philip Martin
In article <01BD226A.52072680spam_OUTrod.wilson>, Rod Wilson
<@spam@rod.wilsonKILLspamBARCLAYS.CO.UK> writes
>Phillip,
>
>This list is for discussing PIC microcontrollers. If you
>are interested in swapping your butt or any other bodily
>part, then I suggest that you post to one of the fetish
>newsgroups ...
>
TeeHee, by the time I saw that mistake it was too late, it had goneeee.
BTW, thanks for all replies, yes the numbers were decimal. I think I was
suffering from wood for trees syndrome, plus a few late nights.

Philip Martin 
Royal Quays If at first you don't succeed, try again. Then quit:
North Shields. no use being a damn fool about it !
PADI AOW+ W.C. Fields
email KILLspamphilipKILLspamphilmart.demon.co.uk
More... (looser matching)
 Last day of these posts
 In 1998
, 1999 only
 Today
 New search...