A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.
|
I'm scratching my head here and need some tips. I want my address label to change dependent on a function, ie: temp_label = lookup_table_1 call temp_label temp_label = lookup_table_2 call temp_label ~~~~~~~~~~~~~~~~~~ lookup_table_1 (stuff) lookup_table_2 (more stuff) Is this valid? Can I address a label, or do I need to know the hex value of the specific address? Maybe there is an easier way to do this? Hope this makes some sense, thanks for any replies. |
|
|
In a message dated 1/22/2004 4:04:44 PM
Eastern Standard Time, j...@yahoo.com writes:I'm scratching my head here and need some tips. I want my address No way - a label is not a variable, therefore itcan not be changed in software. By the same token, you can not create a label in softare, Sid Weaver W4EKQ Port Richey, FL |
|
You may have to load the PC with the literal....
move [lookup_table_2] to PC jrem123 wrote: I'm scratching my head here and need some tips. I want my address --
|
|
If you like thrils, you can do something I have not done in many years, never on a PIC yet. With a self programming PIC, you can rewrite the code on the fly. Try debugging that. Chad --- jrem123 <> wrote: > I'm scratching my head here and need some tips. I want my address > label to change dependent on a function, ie: > temp_label = lookup_table_1 > > call temp_label > > temp_label = lookup_table_2 > > call temp_label > > ~~~~~~~~~~~~~~~~~~ > > lookup_table_1 > (stuff) > lookup_table_2 > (more stuff) > Is this valid? Can I address a label, or do I need to know the hex > value of the specific address? Maybe there is an easier way to do > this? > > Hope this makes some sense, thanks for any replies. __________________________________ |
|
|
|
ahh, I sence that your point is I should rethink the execution of my routines to avoid doing such things. --- In , Chad Russel <chadrussel@y...> wrote: > If you like thrils, you can do something I have not done in many years, > never on a PIC yet. With a self programming PIC, you can rewrite the > code on the fly. Try debugging that. > > Chad > --- jrem123 <jrem123@y...> wrote: > > I'm scratching my head here and need some tips. I want my address > > label to change dependent on a function, ie: > > > > > > temp_label = lookup_table_1 > > > > call temp_label > > > > temp_label = lookup_table_2 > > > > call temp_label > > > > ~~~~~~~~~~~~~~~~~~ > > > > lookup_table_1 > > (stuff) > > lookup_table_2 > > (more stuff) > > > > > > Is this valid? Can I address a label, or do I need to know the hex > > value of the specific address? Maybe there is an easier way to do > > this? > > > > Hope this makes some sense, thanks for any replies. > > > > __________________________________ |
|
> If you like thrils, you can do something I have not done in > many years, > never on a PIC yet. With a self programming PIC, you can rewrite the > code on the fly. Try debugging that. You mean a bootloader? As a 2nd year student I wrote a TSR for MSDOS for managing other TSRs. It switched other TSR's on and off by having the interrupts that they had claimed routed around them (when switched off). I did this by changing the detinations of certain jumps. Had to be carefull when using later processors that had an instruction lookahead fetch! Wouter van Ooijen -- ------------------------------------------- Van Ooijen Technische Informatica: www.voti.nl consultancy, development, PICmicro products |
|
|
|
Bootloaders were one example. Data General had an ingenious one. Because it was a 16 bit machine, and the boot input was 8 bits, they were able to create a bootloader using instructions that only utilized the 1st 8 bits of the each 16 bit word. The 16 bit loader instructions were generated by incrementing the instruction memory locations, until the correct 16 bit instructions were made. When enough 16 bit instructions for a loader were made, it jumped to the 16 bit loader. Chad --- Wouter van Ooijen <> wrote: > > If you like thrils, you can do something I have not done in > > many years, > > never on a PIC yet. With a self programming PIC, you can rewrite > the > > code on the fly. Try debugging that. > > You mean a bootloader? > > As a 2nd year student I wrote a TSR for MSDOS for managing other > TSRs. > It switched other TSR's on and off by having the interrupts that they > had claimed routed around them (when switched off). I did this by > changing the detinations of certain jumps. Had to be carefull when > using > later processors that had an instruction lookahead fetch! > > Wouter van Ooijen > > -- ------------------------------------------- > Van Ooijen Technische Informatica: www.voti.nl > consultancy, development, PICmicro products __________________________________ |
|
----- Original Message ----- From: <> To: <> Sent: Thursday, January 22, 2004 9:08 PM Subject: Re: [piclist] labels > In a message dated 1/22/2004 4:04:44 PM Eastern Standard Time, > writes: > > I'm scratching my head here and need some tips. I want my address > > label to change dependent on a function, ie: > > > > > > No way - a label is not a variable, therefore itcan not be changed in > software. > By the same token, you can not create a label in softare, Yes way - just not with MPASM. XCASM allows you to build and use labels during assembly. These are refered to as dynamic labels. XCASM has assembly variables which you use to manipulate dynamic labels during assembly. e.g. var1 .set 0 var2 .set LABEL("abc_%d": var1) var2 is an assembly variable which has been assigned the dynamic label "abc_0" it could then be use as: var2 rlf acc decfsz count goto var2 XCASM is the assembler used by the XCSB compiler Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler |
|
|
|
You may be able to create dynamic labels with some assemblers but (I believe) the original post was asking how to change the target of a jump using only the assembler when the data needed to make the decision was only known at runtime. Assemblers (all assemblers) can only generate code for what is know at assembly time. How extensively do you want to modify a macro. The MPASM macro language allows for argument passing, text substitution, and conditional assembly. -Mike ----- Original Message ----- From: "Chad Russel" <> To: <> Sent: Thursday, January 22, 2004 6:31 PM Subject: Re: [piclist] labels > I think the work around would be easy enough in MPASM, I assumed an > actual code change during execution was wanted. > > What I wish is to redefine a macro. Will XCASM allow that? MPASM will > not, and I have not figured out a work around. No matter what I have > tried, it wants to throw up all over my builds. :-( > > Chad > > --- sergio masci <> wrote: > > > > ----- Original Message ----- > > From: <> > > To: <> > > Sent: Thursday, January 22, 2004 9:08 PM > > Subject: Re: [piclist] labels > > > > > > > In a message dated 1/22/2004 4:04:44 PM Eastern Standard Time, > > > writes: > > > > > > > > > > I'm scratching my head here and need some tips. I want my > > address > > > > label to change dependent on a function, ie: > > > > > > > > > > > > > > No way - a label is not a variable, therefore itcan not be changed > > in > > > software. > > > By the same token, you can not create a label in softare, > > > > > > > Yes way - just not with MPASM. > > > > XCASM allows you to build and use labels during assembly. These are > > refered > > to as dynamic labels. XCASM has assembly variables which you use to > > manipulate dynamic labels during assembly. > > > > e.g. > > > > var1 .set 0 > > var2 .set LABEL("abc_%d": var1) > > > > var2 is an assembly variable which has been assigned the dynamic > > label > > "abc_0" it could then be use as: > > > > var2 rlf acc > > decfsz count > > goto var2 > > > > XCASM is the assembler used by the XCSB compiler > > > > Regards > > Sergio Masci > > > > http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC > > compiler > __________________________________ > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions |
|
You can implement a table lookup of goto's that will execute the
given function, then just load the function offset enumeration into
W. It'd look something like: movlw LOOKUP_TABLE_1 call temp_label temp_label addwf PCL,F goto lookup_table_1 goto lookup_table_2 ... -Aaron ---- At 01:01 PM 1/22/2004, you wrote: I'm scratching my head here and need some tips. I want my address label to change dependent on a function, ie: temp_label = lookup_table_1 call temp_label temp_label = lookup_table_2 call temp_label ~~~~~~~~~~~~~~~~~~ lookup_table_1 (stuff) lookup_table_2 (more stuff) Is this valid? Can I address a label, or do I need to know the hex value of the specific address? Maybe there is an easier way to do this? Hope this makes some sense, thanks for any replies. to unsubscribe, go to http://www.yahoogroups.com and follow the instructions |
|
I don't think that is possible with a risc-based processor like a PIC. As far as I know, the data-memory and program-memory are separated and it's not possible to write 'self-mutulating-code'. Kees Stenekes. --- Chad Russel <> wrote: > If you like thrils, you can do something I have not > done in many years, > never on a PIC yet. With a self programming PIC, > you can rewrite the > code on the fly. Try debugging that. > > Chad > --- jrem123 <> wrote: > > I'm scratching my head here and need some tips. I > want my address > > label to change dependent on a function, ie: > > > > > > temp_label = lookup_table_1 > > > > call temp_label > > > > temp_label = lookup_table_2 > > > > call temp_label > > > > ~~~~~~~~~~~~~~~~~~ > > > > lookup_table_1 > > (stuff) > > lookup_table_2 > > (more stuff) > > > > > > Is this valid? Can I address a label, or do I > need to know the hex > > value of the specific address? Maybe there is an > easier way to do > > this? > > > > Hope this makes some sense, thanks for any > replies. > > > > __________________________________ __________________________________ |
|
|
|
> I don't think that is possible with a risc-based > processor like a PIC. As far as I know, the > data-memory and program-memory are separated and it's > not possible to write 'self-mutulating-code'. Note that most newer PICs have the capability to write to their code memory. But this is not something you would want to do during 'normal' execution. Such a write takes considerable time, the number of writes is limited (10k?), and the write algorithm (including block factor and whether pre-erase is required) varies between the different chips. But it is very usefull for things like bootloaders and in-circuit debuggers. Wouter van Ooijen -- ------------------------------------------- Van Ooijen Technische Informatica: www.voti.nl consultancy, development, PICmicro products |
|
|
|
Hey, I didn't knew that, but that's because I only work with 16F628's and 12F629's, and not the 'newer PICs'. B.t.w. Wouter, when will your stock of 628A's be refilled? I wanted to order some at your shop, but saw they were sold out. Kees. --- Wouter van Ooijen <> wrote: > > I don't think that is possible with a risc-based > > processor like a PIC. As far as I know, the > > data-memory and program-memory are separated and > it's > > not possible to write 'self-mutulating-code'. > > Note that most newer PICs have the capability to > write to their code > memory. But this is not something you would want to > do during 'normal' > execution. Such a write takes considerable time, the > number of writes is > limited (10k?), and the write algorithm (including > block factor and > whether pre-erase is required) varies between the > different chips. But > it is very usefull for things like bootloaders and > in-circuit debuggers. > > Wouter van Ooijen > > -- ------------------------------------------- > Van Ooijen Technische Informatica: www.voti.nl > consultancy, development, PICmicro products __________________________________ |
|
|
|
> Hey, I didn't knew that, but that's because I only > work with 16F628's and 12F629's, and not the 'newer > PICs'. To be a bit more precise: this feature is in most 40 and 28 pin chips, and in all 18F's, AFAIK not in any 8 or 14 pin chips, but in some 18 pin chips (like 16F818/819). > B.t.w. Wouter, when will your stock of 628A's be > refilled? I wanted to order some at your shop, but saw > they were sold out. A big package from my supllier arrived this morning, so most chips are available again. Now I am wiating for some batches of PCBs for the Wisp628 and other kits. Wouter van Ooijen -- ------------------------------------------- Van Ooijen Technische Informatica: www.voti.nl consultancy, development, PICmicro products |
|
----- Original Message ----- From: Chad Russel <> To: <> Sent: Friday, January 23, 2004 1:31 AM Subject: Re: [piclist] labels > I think the work around would be easy enough in MPASM, I assumed an > actual code change during execution was wanted. > > What I wish is to redefine a macro. Will XCASM allow that? MPASM will > not, and I have not figured out a work around. No matter what I have > tried, it wants to throw up all over my builds. :-( > > Chad No XCASM will not "currently" allow you to redefine a macro. It would be simple to implement dynamic macros in a manor similar to dynamic labels. What is it that you are trying to do exactly? Perhaps we could suggest a solution if we knew what you are trying to do. Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler |
|
|
|
----- Original Message ----- From: Wouter van Ooijen <> To: <> Sent: Friday, January 23, 2004 10:50 AM Subject: RE: [piclist] labels > > I don't think that is possible with a risc-based > > processor like a PIC. As far as I know, the > > data-memory and program-memory are separated and it's > > not possible to write 'self-mutulating-code'. > > Note that most newer PICs have the capability to write to their code > memory. But this is not something you would want to do during 'normal' > execution. Such a write takes considerable time, the number of writes is > limited (10k?), and the write algorithm (including block factor and Clarification: By limited Wouter means that you can only write to a program location a relatively small number of times before that location starts having problems holding what you write into it. It kind of wears out. If you try to use it like a normal RAM location you are asking for trouble. > whether pre-erase is required) varies between the different chips. But > it is very usefull for things like bootloaders and in-circuit debuggers. > > Wouter van Ooijen > > -- ------------------------------------------- > Van Ooijen Technische Informatica: www.voti.nl > consultancy, development, PICmicro products |
|
----- Original Message ----- From: jrem123 <> To: <> Sent: Thursday, January 22, 2004 9:01 PM Subject: [piclist] labels > I'm scratching my head here and need some tips. I want my address > label to change dependent on a function, ie: > temp_label = lookup_table_1 > > call temp_label > > temp_label = lookup_table_2 > > call temp_label > > ~~~~~~~~~~~~~~~~~~ > > lookup_table_1 > (stuff) > lookup_table_2 > (more stuff) > Is this valid? Can I address a label, or do I need to know the hex > value of the specific address? Maybe there is an easier way to do > this? > > Hope this makes some sense, thanks for any replies. Ah the original question: Yes you can! The simplest way is to use a 16 bit pointer to the table and an 8 bit index into that table Try this: ; table_ptr = lookup_table_1 movlw HI(lookup_table_1) movwf table_ptr+1 movlw LO(lookup_table_1) movwf table_ptr+0 ; J is the element of the lookup table we want movf J,w movwf indx ; fred is the function that will need to do the lookup call fred ;--- ; table_ptr = lookup_table_2 movlw HI(lookup_table_2) movwf table_ptr+1 movlw LO(lookup_table_2) movwf table_ptr+0 ; J is the element of the lookup table we want movf J,w movwf indx ; fred is the function that will need to do the lookup call fred loop goto loop ;--- ; parameters to fred are table_ptr and indx fred: ; ; do stuff ; call lookup ; ; do more stuff ; return ;--- lookup movf table_ptr+1,w movwf PCLATH movf table_ptr+0,w addwf indx,w btfsc STATUS,C incf PCLATH movwf PCL lookup_table_1 retlw 1 retlw 2 retlw 3 retlw 4 retlw 5 lookup_table_2 retlw 10 retlw 20 retlw 30 retlw 40 retlw 50 Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler |
|
|
|
----- Original Message ----- From: Chad Russel <> To: <> Sent: Friday, January 23, 2004 5:34 PM Subject: [piclist] Re: labels > --- In , "sergio masci" <smypl@x> wrote: > > > > ----- Original Message ----- > > From: Chad Russel <chadrussel@y...> > > To: <> > > Sent: Friday, January 23, 2004 1:31 AM > > Subject: Re: [piclist] labels > > > > > > > I think the work around would be easy enough in MPASM, I assumed an > > > actual code change during execution was wanted. > > > > > > What I wish is to redefine a macro. Will XCASM allow that? MPASM > will > > > not, and I have not figured out a work around. No matter what I have > > > tried, it wants to throw up all over my builds. :-( > > > > > > Chad > > > > No XCASM will not "currently" allow you to redefine a macro. It would be > > simple to implement dynamic macros in a manor similar to dynamic labels. > > > > What is it that you are trying to do exactly? Perhaps we could suggest a > > solution if we knew what you are trying to do. > > > > Regards > > Sergio Masci > > Very simple. The first macro instance produces an expansion, then > next and following instances produces a call to the first. I have > done this before, by following the macro definition with a new > definition, but MPLAB sees it one way the first pass, and the second > way the second pass, producing errors. > > Chad Are you saying that you have a macro that adds code to the end of itself? You could do something simple using assembler variables like: var .set 0 var1 .set 0 var2 .set 0 FRED .macro arg1 var1 .set var2 var2 .set LABEL("xlab_%d": var) ; some dummy code var2 incf arg1 .if var != 0 ; jump to previous instance goto var1 .endif var .set var + 1 .endm Or IF you can use multiple sections in MPASM (sorry don't MPASM that well and I haven't touched it in years but most other assemblers I've used including xcasm will let you do this) you might be able to do something like: FRED .macro arg1 .sect special_sect_1 ; some dummy code incf arg1 .sect original_code_sect .endm So all the code generated by FRED would go into a seperate section. You could simply add a label to the start of the section, a "return" instruction to the end and simply call it. Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler |
|
|
|
----- Original Message ----- From: Chad Russel <> To: <> Sent: Friday, January 23, 2004 7:23 PM Subject: Re: [piclist] Re: labels > I have learned today, that 1 million EEPROM writes is not very many > when you accidently do it every 2 millisecond and leave it running > overnight. :) > > I have not tried it using an assembly variable. I have tried it using > the "If Defined" function, which does not work, so I thing the assembly > variable will end up doing the same. I get 1st pass, 2nd pass > addressing errors. > > The way I am used to is as follows: > > Sergio MACRO arg1, arg2 > LOCAL exit > > GOTO exit > > Sergio_add: instructions here > RETURN > > exit: CALL Sergio_add > > Sergio MACRO arg1, arg2 > CALL Sergio_add > ENDM > ENDM > > The first time the macro is called it expands totally, but also > redefines itself as a call. Subsequently it expands to only a call. I > may have to do some more playing. > > Chad Ok, I've done a bit of digging in the MASM manual and apparently MPASM does have assembler variables (just restricted), so you should be able to do the following: FRED MACRO arg1, arg2 LOCAL exit if fred_var == 0 fred_var set 1 goto exit fred_add: instructions here return exit: endif call fred_add endm At the very start of your program you will need to define fred_var as a variable e.g. fred_var set 0 Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler |
|
----- Original Message ----- From: northwoodsfisherman <> To: <> Sent: Friday, January 23, 2004 1:58 PM Subject: [piclist] Re: labels > --- In , "sergio masci" <smypl@x> wrote: > > I have a similiar problem in doing a read of program memory from my > program (Using a 16F628). I want to store a initialized ascii string > that will be sent to the UART. But the only way I found to read it > out of program memory is use the method outlined in AN556 (On table > reads) on the Microchip site. The snippet goes something like this.. > > ; First initialize offset > movlw offset > call Table > ; then send it to the UART > .... other stuff > Table addwf PCL,F > retlw 'A' ;String to send out > retlw 's' > > This works but is very wasteful, the retlw takes one program word per > character. Anyone know a cleaner way to read program memory at run > time?? If so could put initialized string at end of program memory > using data directive. > > Bob Ball > WB8WGA Programs in a 628 can only access the content of the program memory via execution. They cannot read from or write to it. The retlw instruction is the most efficient way of storeing a data table in the 628. The MPASM DT directive allows you declare strings stored in the program memory as a sequence of retlw instructions e.g. dt "hello", 0 is equivalent to retlw 'h' retlw 'e' retlw 'l' retlw 'l' retlw 'o' retlw 0 You could write macros to make using strings "look" cleaner. Regards Sergio Masci http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler |