----- Original Message ----- From: David V. Fansler To: 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. > 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 > DFansler@MindSpring.com > www.DV-Fansler.com > 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 listserv@mitvma.mit.edu with SET PICList DIGEST in the body