At 10:12 AM 12/11/02 -0500, you wrote: >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 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. >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. 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" speff@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 listserv@mitvma.mit.edu with SET PICList DIGEST in the body