What Register To Use When Storing A Long String In Assembly
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
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
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.
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, expectmovf 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.
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
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).
RE: Variable Sizes and Strings in Assembly 2007/08/24 06:39:59 (permalink)
Thanks again everyone for the helpul info
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
0 Response to "What Register To Use When Storing A Long String In Assembly"
Post a Comment