Searching \ for '[PIC]: Program layout results in haywire operation' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Program layout results in haywire operation'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Program layout results in haywire operation'
2002\10\04@063951 by Tim H.

picon face
Hello,

It's been awhile since I've been on the list but it's always nice to be back. I have ineresting problem that's getting the best of me. After a few hours of Google-ing I realize I have to swallow my pride and ask the experts. If you read through this and reply, kudos to you!

I have an application where a 16F628 is controlling an ISD2560 ChipCorderT I've written the code, debugged it and it works just fine. There's a possibility that the code I wrote to control the ISD chip will be used some time in the future. So, the person I'm writing it for wants that kind of code in "modules." I figure it's ok to put this code into an INC file and add an include statement at the END of my main code. The code works when it's laid out like this:

org    0
goto    MAIN

MAIN
....code here....
A call to delay which is in ISD.inc as well as the actual ISD interface code.

include ISD.inc


Contents of ISD.inc:

..Delay function...return (return to calling routine) --- the .lst file says Delay begins @ 0x002E
..ISD code....return -- .lst says this begins at 0x003F

end program

If I compile this like it's laid out (in this order) it works fine. Suppose I swap the position in memory of "Delay" with "ISD"? So, the ISD.inc layout will look like this:

...ISD code....return -- the .lst file says this code resides at 0x002E
...Delay function...return -- .lst file says this begins at 0x004F

So, I hit CTRL+S, CTRL+F10 (to build project); build successful. Burn it to 16F628, put it in circuit and the code will play a piece of the required message (on the ISD chip) but then it seems to jump to another point in the program where another message is played that shouldn't be. It just pretty much goes haywire. It seems like the ISD code is doing it's thing, but the data that's used to determine WHICH message to play is corrupt.

The code itself isn't very large so I'm sure it's not crossing page boundaries. And I only use a few file registers. I'm hoping I've overlooked something obvious.
So, the question is, why does changing the physical location of routines in a "module" affect the program's operation?

If you've read this far, I appreciate your time.

Thanks in advance!

Tim H.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\10\04@073334 by Alan B. Pearce

face picon face
>It's been awhile since I've been on the list but it's always
>nice to be back. I have ineresting problem that's getting the
>best of me. After a few hours of Google-ing I realize I have
>to swallow my pride and ask the experts. If you read through
>this and reply, kudos to you!

Goto http://www.embedinc.com/pic/ and get the development tools from the
software downloads section at the bottom of the page. Olin's modular system
is ideal for what you want.

As a bonus you get all sorts of macros that assist with keeping track of
bank and page switching, and means that the linker does all the dirty work
of making sure code doesn't cross page boundaries without producing an
error. It is not totally foolproof, but then nothing is unless the assembler
keeps accurate track of the banks for you. This is as near as you will get
to that utopia.

He also has a complete example project for a Halloween toy that illustrates
admirably how to use the tools.

The kudos should go to Olin for the work he has put into the tools, and
making it available.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\10\04@074912 by Geo

flavicon
face
On 4 Oct 2002, at 3:28, Tim H. wrote:

> org    0
> goto    MAIN
>
> MAIN
> ....code here....
> A call to delay which is in ISD.inc as well as the actual ISD interface code.

You have not indicated here if the main part ends or just runs into the next
routine...

> include ISD.inc
> Contents of ISD.inc:
> ..Delay function...return (return to calling routine) --- the .lst file says Delay begins @ 0x002E
> ..ISD code....return -- .lst says this begins at 0x003F
> end program

George Smith

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\10\04@075949 by Russell McMahon

face
flavicon
face
/So, the question is, why does changing the physical location of routines in
a "module" affect the program's operation?/

Have you included a subroutine return at all appropriate places? If not,
then what the code runs into next will alter its operation. It may or may
not then operate correctly.


       RM

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\10\04@090459 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,
Tim H. wrote:
<snip>
>
>org    0
>goto    MAIN
>
>MAIN
>....code here....
>A call to delay which is in ISD.inc as well as the actual ISD interface
code.
>
>include ISD.inc
>
<snip>
Well, you are trying to use the include file function of the assembler
to something
it was not really meant for. What you want to use though is
're-locatable' modules or code.
Someone mentioned Olin's published work, I haven't looked at it myself
but I belive there
are alot of things there that could help you. However, read up on the
re-locatable code
in the linker manual.
Basiclly you need to change how you 'allocate' (reserv) memory, use:

MY_MODULE       UDATA
MyVar   RES 1

Instead of the absolute:
CBLOCK  0xXXX
       MyVar:1

UDATA needs to be defined in a linker control file, there are several
available
in the mplab directories i belive.
Then you need to add GLOBAL to function that is to be exposed outside
your module:

MY_NEAT_FUNC
       GLOBAL MY_NEAT_FUNC
       ;code...

Then write an .inc file containing the EXTERN keyword for your module:

       EXTERN  MY_NEAT_FUNC

Now include this inc file in the module you need to access it and leave
the rest to the linker.
The module containing the function ofcource needs to be added to the
project.

Fun stuff :)

/Tony

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\10\04@092532 by Tim H.

picon face
Hello (to everyone who replied),

----- Original Message -----
From: "Geo" <spam_OUTlintechTakeThisOuTspamBLUEYONDER.CO.UK>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Friday, October 04, 2002 4:43 AM
Subject: Re: [PIC]: Program layout results in haywire operation?


> On 4 Oct 2002, at 3:28, Tim H. wrote:
>
> > org    0
> > goto    MAIN
> >
> > MAIN
> > ....code here....
> > A call to delay which is in ISD.inc as well as the actual ISD interface
code.
>
> You have not indicated here if the main part ends or just runs into the
next
> routine...

The MAIN code initializes the ports, turns off the comparators, etc. It then
drops down into an endless loop looking for a switch input on PORTB. Upon
input, it determines which PORTB pin was pressed and then plays the
corresponding message on the ISD. FWIW, I'm using the message cueing mode of
the ISD chip to select/play the messages.

All of the called subroutines end with the appropriate RETURN. I can't, for
the life of me figure out why changing the location (order) of Delay and ISD
code results in totally different operation.

For anyone that's interested, I took notes on which layouts worked, and
which ones didn't. Here are the results:

http://picmcu.netfirms.com/picpeeve.gif

For the "modules" where both are red, it means they're both in the same INC
file (yes, I know that isn't the purpose of an INC file).

Thanks,

Tim H.


>
> > include ISD.inc
> > Contents of ISD.inc:
> > ..Delay function...return (return to calling routine) --- the .lst file
says Delay begins @ 0x002E
{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...