On Mon, 15 Jan 2001, Tony Nixon wrote: > How do you decide the end of a subroutine? > > Test movf Value,W > xorwf Tval,W > btfsc STATUS,Z > retlw 'Y' > > movf Value2,W > btfsc STATUS,Z > retlw 'N' > retlw '?' if this were written in C: char Test(void) { if(Value == Tval) return 'Y'; if(Value2) return 'N'; return '?'; } It's clear from this where the end of the function is. But you're right, the demarcation of functions is going to be difficult to ascertain algorithmically. > > Surely there would need to be markers added to the code. > > ; [SubStart - Test] > > Test movf Value,W > xorwf Tval,W > btfsc STATUS,Z > retlw 'Y' > > movf Value2,W > btfsc STATUS,Z > retlw 'N' > retlw '?' > > ; [SubEnd - Test] > > Probably be a nightmare with 'spagetti code' - which can be bad > practice, but is sometimes unnavoidable. This is one solution that works really well. In fact, in the SDCC PIC port I have just that sort of information availailable. One way to determine where a function begins is to follow this simple algorithm: 1) Find the destination of every call and arbitrarily say that this is the entry of a function. 2) Examine the instruction preceeding the entry point. If it is not a return, then the entry point is NOT the start of a function. If it is a return, then it will be the start of the function if instruction preceeding the return is not a btfss/btfsc. .... clrf x return f1: ; start of a function clrf Tval f2: ; not the start of a function movf Value,W xorwf Tval,W skpnz retlw 'Y' f3: ; not the start of a function movf Value2,w skpnz retlw 'N' retlw '?' Even though f2 and f3 are not the start of functions, they may still be called from some other address in the PIC. That's the beauty of assembly language; anything goes! > > Test movf Value,W > xorwf Tval,W > btfsc STATUS,Z > retlw 'Y' > > movf Value2,W > btfsc STATUS,Z > retlw '?' > > movlw High(Test2) > movwf PCLATH > goto Test2 This is a more complicated case. This kind of code is what can get generated by a C-compiler's tail merging algorithm (right James?). In this case, the compiler discovers two functions that end identically. Rather than duplicating the code, the compiler decides to generate only one copy. One of the functions jumps to the common ending of the other. I'm sure if we think about for a few minutes, we'll find boundary conditions that defy categorization. (My software PWM routine come sto mind). However, it's still possible to determine a majority the cases. Scott -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.