Searching \ for '[PIC]:String Copy in ASM' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=asm
Search entire site for: 'String Copy in ASM'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:String Copy in ASM'
2002\12\11@102605 by DFansler

picon face
I am working on a project where I am receiving strings of data via RS-232.
The data is NMEA sentences, of which I do not need all data from every
sentence.  Therefore I am parsing the data as it is received and writing the
data into a buffer of on board RAM (16F873).  Once the entire sentence is
received, I am copying data from the buffer and placing it in different
locations from where it will be displayed.  Some of the sentences have a
"data valid" flag, that often is not the first byte of data, so I need to
place the data in temp storage until I am sure the data is valid.

The problem I am currently addressing is copying string data from one
location to another - in assembler.  Using direct addressing would make the
program way to large for the amount of program memory on the 16F873.  There
are 35 pieces of data (from 1 byte to 10 bytes in length) in 24 sentences
that can be up to 80 bytes long.  Therefore I am using indirect addressing.
The problem with indirect addressing is that, as I understand it, you can
only be indirectly addressing one place at the time.  The method for
handling this that I have come up with is to:

1 set up the FSR for the byte to be read
2 read the byte using INDF and store in a temp location - check for end of
string - exit if EOS
3 inc the FSR and save into another temp location (FSR_READ)
4 load FSR with the register to write to (stored in FSR_WRITE)
5 read the byte from its temp location
6 write the byte using INDF
7 inc FSR and save FSR in FSR_WRITE
8 load FSR with the register to read from (FSR_READ)
9 loop back to #2

Any one have a better idea, or has anyone done string copying in assembler
before?  I searched the archives and did not find anything.  I want to use
assembler - not C, and I wish to stay with the 16F87x series.

Thanks,
David

David V. Fansler
spam_OUTDFanslerTakeThisOuTspamMindSpring.com
http://www.DV-Fansler.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


2002\12\11@110512 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,
David Fansler wrote:
<snip>
>The problem I am currently addressing is copying string data from one
>location to another - in assembler.  Using direct addressing would make
the
>program way to large for the amount of program memory on the 16F873.
There
>are 35 pieces of data (from 1 byte to 10 bytes in length) in 24
sentences
>that can be up to 80 bytes long.  Therefore I am using indirect
addressing.
>The problem with indirect addressing is that, as I understand it, you
can
>only be indirectly addressing one place at the time.  The method for
>handling this that I have come up with is to:
<snip>

Well if you look at how the indirect adressing is composed you'll find
that is you have two buffer in separate banks which are aligned (
same offset within bank and same length ) and the bank selection bit's
RP0 and RP1 only differs in one bit ( for example bank0 & bank1
or bank2 & bank3 ) you can switch the indf register between these
registers
by only using one bsf/bcf instruction. Drawback: have to have same length and be in synch.

/Tony

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2002\12\11@120732 by Spehro Pefhany

picon face
At 10:12 AM 12/11/02 -0500, you wrote:
{Quote hidden}

If you are using C-like null-terminated strings you'll want to write
the terminating null into the target string. You can check for the
null after it is written.

{Quote hidden}

Yes, that's essentially what you'll have to do, as the PIC only has
one index register, you'll have to share it. It's even uglier because
everything has to go through W, so you need another temp location, as
you say, to hold the data. About a dozen instructions total, and about 13
cycles per byte copied, including the terminating null, unless there is
some trick I've missed (like the one I see that Tony has just mentioned,
which isn't general, but a neat trick nonetheless). Similarly you might
be able to do something with flipping bits of the FSR if the string origins
were appropriately aligned, which could leave w intact until it's
written.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam.....interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2002\12\11@125336 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,
David Fansler wrote:
<snip>
>Any one have a better idea, or has anyone done string copying in
assembler
>before?  I searched the archives and did not find anything.  I want to
use
>assembler - not C, and I wish to stay with the 16F87x series.
<snip>

Actually I really think an 18Fxx would be better for this project, mind
you i don't know the specifics. But I reccon that the price difference
is
not that large and the features would help you alot.
Are there any particular reasons you are 'stuck' with the 16F8xx series
?

/Tony

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2002\12\11@130137 by Sergio Masci

picon face
----- Original Message -----
From: David V. Fansler <@spam@DFanslerKILLspamspamMINDSPRING.COM>
To: <KILLspamPICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Wednesday, December 11, 2002 3:12 PM
Subject: [PIC]:String Copy in ASM


> I am working on a project where I am receiving strings of data via RS-232.
> The data is NMEA sentences, of which I do not need all data from every
> sentence.  Therefore I am parsing the data as it is received and writing
the
> data into a buffer of on board RAM (16F873).  Once the entire sentence is
> received, I am copying data from the buffer and placing it in different
> locations from where it will be displayed.  Some of the sentences have a
> "data valid" flag, that often is not the first byte of data, so I need to
> place the data in temp storage until I am sure the data is valid.
>
> The problem I am currently addressing is copying string data from one
> location to another - in assembler.  Using direct addressing would make
the
> program way to large for the amount of program memory on the 16F873.
There
> are 35 pieces of data (from 1 byte to 10 bytes in length) in 24 sentences
> that can be up to 80 bytes long.  Therefore I am using indirect
addressing.
{Quote hidden}

try using a small temporary buffer as follows
; j = pointer to source string
; k = pointer to destiniation string

lab1 movf j,w
movwf FSR

movf INDF,w
incf FSR
movwf tmp+0
movf INDF,w
incf FSR
movwf tmp+1
movf INDF,w
incf FSR
movwf tmp+2
movf INDF,w
incf FSR
movwf tmp+3

; add more stages here if required

movlw 4
addwf j

movf k,w
movwf FSR

movf tmp+0,w
movwf INDF
btfsc STATUS,Z
goto lab99
incf FSR
movf tmp+1,w
movwf INDF
btfsc STATUS,Z
goto lab99
incf FSR
movf tmp+2,w
movwf INDF
btfsc STATUS,Z
goto lab99
incf FSR
movf tmp+3,w
movwf INDF
btfsc STATUS,Z
goto lab99
incf FSR

; add more stages here if required

movlw 4
addwf k

goto lab1

lab99

Regards
Sergio Masci

http://www.xcprod.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


2002\12\11@131040 by DFansler

picon face
Primarily I want to use the 16F87x because I have the ClearMathias emulator
and have found it to be a wonderful tool for debugging.  I confess that I
have been dependent on ICEs since the early 80's when I was working with RCA
1800 series processors.  At some point I would like to move into the 18F
series, but will wait till I can afford an ICE for them.
Thanks

David V. Fansler
TakeThisOuTDFanslerEraseMEspamspam_OUTMindSpring.com
http://www.DV-Fansler.com

{Original Message removed}

2002\12\11@132251 by Olin Lathrop

face picon face
> 1 set up the FSR for the byte to be read
> 2 read the byte using INDF and store in a temp location - check for end
of
> string - exit if EOS
> 3 inc the FSR and save into another temp location (FSR_READ)

You can just INC FSR_READ in place since it will have the save value as
FSR.

> 4 load FSR with the register to write to (stored in FSR_WRITE)
> 5 read the byte from its temp location
> 6 write the byte using INDF
> 7 inc FSR and save FSR in FSR_WRITE

Same comment as above.

> 8 load FSR with the register to read from (FSR_READ)
> 9 loop back to #2

If you need higher efficiency, you can copy a block of bytes at a time.
FSR only needs to be swapped back and forth per block, not per byte.  Even
better would be to use an 18 family PIC.  These have multiple FSRs and
they can do auto-increment.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2002\12\11@132705 by Andrew Warren

flavicon
face
David V. Fansler <DFanslerEraseMEspam.....mindspring.com> wrote:

> Any one have a better idea, or has anyone done string copying in
> assembler before?

David:

If you're copying a string that starts at SOURCE to a location called
DEST, you can eliminate the need for temporary storage of the FSR by
doing this:

1.  Point FSR at SOURCE.
2.  Read INDF and store in a temp location.
3.  Check for EOS, exit if necessary.
4.  FSR = FSR + (DEST-SOURCE).
5.  Read TEMP locvation and write it to INDF.
6.  FSR = FSR + (SOURCE-DEST).
7.  Loop back to 2.

-Andy

=== Andrew Warren -- EraseMEaiwspamcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservEraseMEspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body


2002\12\11@132707 by Olin Lathrop

face picon face
>>
Well if you look at how the indirect adressing is composed you'll find
that is you have two buffer in separate banks which are aligned (
same offset within bank and same length ) and the bank selection bit's
RP0 and RP1 only differs in one bit ( for example bank0 & bank1
or bank2 & bank3 ) you can switch the indf register between these
registers
by only using one bsf/bcf instruction.
<<

Indirect addressing (using FSR and INDF) is not dependent on the RP0 and
RP1 bits.  There is a separate IRP bit to select the indirect register
bank.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspam_OUTspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2002\12\11@133113 by Olin Lathrop

face picon face
> >3 inc the FSR and save into another temp location (FSR_READ)
> >4 load FSR with the register to write to (stored in FSR_WRITE)
> >5 read the byte from its temp location
> >6 write the byte using INDF
> >7 inc FSR and save FSR in FSR_WRITE
> >8 load FSR with the register to read from (FSR_READ)
> >9 loop back to #2

I forgot to point out earlier that this assumes both buffers are in the
same indirect bank.  It gets even more ugly when they are not because the
IRP bit needs to be set each time FSR is set in the general case.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservTakeThisOuTspamspammitvma.mit.edu with SET PICList DIGEST in the body


2002\12\12@050504 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,

Olin Lathrop wrote:
>Indirect addressing (using FSR and INDF) is not dependent on the RP0
and
>RP1 bits.  There is a separate IRP bit to select the indirect register
>bank.

Yes, ofcource ,my bad. But the 'techniqe' would still work.

David Fansler wrote:
>Primarily I want to use the 16F87x because I have the ClearMathias
emulator
>and have found it to be a wonderful tool for debugging.  I confess that
I
>have been dependent on ICEs since the early 80's when I was working
with RCA
>1800 series processors.  At some point I would like to move into the
18F
>series, but will wait till I can afford an ICE for them.
>Thanks

Ok, but I have ICE2000+various modules, 'old' ICD and the new ICD2. I
belive
that the new ICD2 is really a great tool. Ofcource the ICE gives alot of
more
power and view of the internals but I still use the ICD2 for many
debugging tasks.
And even though you might eventually purchase the ICE you are still
better off
owning both as the ICD2 can be used for (re-)programming and in field
debugging.
I would suggest that you atleast consider the ICD2 and using the 18Fxx
series.

/Tony

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspamspamspamBeGonemitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...