banner



What Register To Use When Storing A Long String In Assembly

rpmorrow

Junior Member

  • Full Posts : 100
  • Reward points : 0
  • Joined: 2007/07/27 06:56:34
  • Location: UK
  • Status: offline

Variable Sizes and Strings in Associates

Hi, I accept a couple of questions relating to storing strings in variables and counting characters.

I'1000 writing a routine to send a discussion via a serial port. The code below shows how i'k currently sending stuff. The CALL to 'TransmitData' obviously merely handles the transmitting of the grapheme.

   MOVLW 'O'                    ; Copy 'O' into W
MOVWF txByte                ; Re-create 'O' into txByte
Telephone call TransmitData            ; Transport the char
MOVLW 'M'                    ; Copy 'One thousand' into W
MOVWF txByte                ; Copy 'K' into txByte
Telephone call TransmitData            ; Send the char

Now for sending just 'OK' information technology's not too bad, only if I wan to send a big word or scentence, information technology would be a lot of repeated code. I was wondering....

1. Tin can I put a whole word (e.g. Hello) into a variable in assembly or can they only hold a single byte?
2. How could I test for the number of chars in this variable then I could do a loop based on that number?

This would allow me to pass a discussion to a routine and have it send information technology out one char at a fourth dimension. If I can't practice it similar that, does anyone know a good approach to this, or is the method i'm currently using the only option?

post edited by rpmorrow - 2007/08/24 03:07:21

siriharry

Starting Member

  • Total Posts : 32
  • Advantage points : 0
  • Joined: 2007/07/25 04:38:43
  • Location: 0
  • Status: offline

RE: Variable Sizes and Strings in Assembly 2007/08/24 03:21:21 (permalink)

if the data u want to ship is a constant string ,then use program retentiveness to store the cord and phone call in the program

Olin Lathrop

Super Member

  • Total Posts : 7463
  • Advantage points : 0
  • Joined: 2004/02/26 17:59:01
  • Location: Littleton Massachusetts
  • Condition: offline

RE: Variable Sizes and Strings in Assembly 2007/08/24 04:35:48 (permalink)

Can I put a whole word (eastward.g. How-do-you-do) into a variable in assembly or can they only concur a unmarried byte?

RAM is organized into bytes, which can concord unmarried characters.  Yous can use a agglomeration of RAM locations to hold multiple bytes.  Whether yous consider such a buffer a unmarried "variable" or is upwards to you.

Nevertheless if the content of the strings is known at assembly fourth dimension, it would exist improve to shop them in program memory.  I ordinarily store such strings with a leading length byte followed by that number of data bytes.  And so it'southward easy to write a routine you pass a programme memory address to that grabs the length byte at that accost then writes out that many subsequent bytes.

How could I test for the number of chars in this variable so I could practice a loop based on that number?

One scheme is to shop a length byte every bit I mentioned higher up.  If you know that your strings will never incorporate a certain byte value (like 0), you tin use it equally a stop of string marker.  In that example you don't count at all, just go on going until you hit the finish of string marker.

bob_barr

Super Member

  • Total Posts : 5428
  • Advantage points : 0
  • Joined: 2003/11/07 12:35:23
  • Location: Morgan Hill, CA
  • Status: offline

RE: Variable Sizes and Strings in Assembly 2007/08/24 04:44:37 (permalink)

The W register is a perfectly valid mode to pass data to a subroutine. What does your 'TransmitData' routine look like? If it'southward like nigh that I've seen, it has code something similar this:

                    
TransmitData:
btfss    TXSTA, TXIF    ; OK to send byte?
goto     TransmitData   ; no, expect

    movf     txData, due west      ; ** this isn't needed, Westward hasn't changed **
movwf    TXREG          ; send the byte
render

If that's the case, there's no need to perform the 'movwf txByte' at all, much less each time the transmit routine is called. If you actually practice need to store the byte, that could exist done as the outset instruction on entry to the transmit routine.

While it's always skilful to learn from i's mistakes, it's much easier to larn from the mistakes of others.
Please don't PM me with technical questions. I'll be quite happy to help (if I can) on the forums.

Mariano H. Caballero

Senior Member

  • Total Posts : 155
  • Reward points : 0
  • Joined: 2005/10/fourteen 05:26:52
  • Location: Buenos Aires, Argentina
  • Status: offline

RE: Variable Sizes and Strings in Assembly 2007/08/24 04:47:00 (permalink)

Hi rpmorrow, you lot can reserve a infinite in your retention map, with a size according to the max size of the max word that you want to transmit, and use a pointer to know which is the side by side character to ship to the UART. you lot besides may need a counter to know how many words you have in the buffer, or you tin use some special character to recognize the end of the word (for example ETX = [0x03]).

Hope it help.

Regards

DarioG

Allmächtig.

  • Total Posts : 54081
  • Advantage points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline

RE: Variable Sizes and Strings in Assembly 2007/08/24 05:45:13 (permalink)

ORIGINAL: rpmorrow
i. Can I put a whole discussion (e.one thousand. Hello) into a variable in assembly or tin can they only hold a single byte?

Besides all other posts, you can use DT or DA directives to store strings in Program Memory (DT used to be fine in 16F serial without the capability of reading their memory, another directive is more adapt in 18F parts):

Something like:

                    
mystring da "pippo",0

and and so apply TBLRD instruction and related registers (TBLPTRx).

rpmorrow

Junior Member

  • Full Posts : 100
  • Reward points : 0
  • Joined: 2007/07/27 06:56:34
  • Location: UK
  • Status: offline

RE: Variable Sizes and Strings in Assembly 2007/08/24 06:39:59 (permalink)

Thanks again everyone for the helpul info

K8LH

Super Fellow member

  • Total Posts : 1888
  • Reward points : 0
  • Joined: 2004/03/26 05:12:34
  • Location: Michigan, Us
  • Condition: offline

RE: Variable Sizes and Strings in Assembly 2007/08/25 04:23:24 (permalink)

Here's a method for 18F' devices that I utilize for storing strings in-line with my code.

Mike

                    
;  _Print macro
;
_Print  MACRO   str             ; print in-line string macro
call    PutString       ;
db      str,0
ENDM
;
;  usage examples
;
_Print  "Satellite AOS:\northward\r"
_Print  "Satellite LOS:\n\r"
;

;******************************************************************
;
;  PutString subroutine - print in-line string via Stack and TBLPTR
;
;  string must exist terminated with a 00 byte and does not need
;  to be word aligned
;
PutString
movff   TOSL,TBLPTRL    ; copy return address into TBLPTR
movff   TOSH,TBLPTRH    ;
clrf    TBLPTRU        ; presume PIC with < 64-KB
PutNext
tblrd   *+              ; go far-line cord character
movf    TABLAT,Due west        ; last character (00)?
bz      PutExit         ; yes, exit, else
rcall   Put232          ; impress character
bra     PutNext         ; and exercise some other
PutExit
btfsc   TBLPTRL,0       ; odd address?
tblrd   *+              ; yes, make it even (set PC)
movf    TBLPTRH,W       ; setup new render address
movwf   TOSH            ;
movf    TBLPTRL,Westward       ;
movwf   TOSL            ;
return                  ;
;
;******************************************************************


Source: https://www.microchip.com/forums/m277380.aspx

Posted by: normanevat1982.blogspot.com

Related Posts

0 Response to "What Register To Use When Storing A Long String In Assembly"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel