Program jumping into include file on start

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
I'll post the code if needed, but for now I'll see if I'm breaking some general rule here.

I'm porting some floating point routines from Microchip's application notes (that use 16C and 17C) over to the 18F. Long story short, it's compiling without errors, but instead of following the "ORG 0 then GOTO START" and actually going to START, it is jumping directly into a subroutine at the top of one of my include files. If I run the simulator I get a stack underflow error whenever it finally reaches the "retlw."

I'm using multiple include files because the app notes had several of them and I've just fixed what I needed to fix.

Looking at the map file it shows the subroutine label in the include file that it keeps going to as address 00000. I'm not sure why, or how to work around this.

I should add that nomatter where I put that include file in the code, the simulator always pulls it up first. There is NOT an ORG directive within the include file. MPLAB is completely skipping over the "ORG 0" I've got in the code.
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
I don't really know C. Perhaps one day I will, but for now I want to keep writing assembly.

It really is not hard to learn. If you know assembler, you should have no problem with C.

I have not used assembler in years. I got started with machine code. When I got a macro assembler, I could not believe how easy it was. :) I have to admit there is a certain charm to assembler.
 

be80be

Joined Jul 5, 2008
2,072
You no there two ways to handle include files But thats a book so maybe this will help
The specified file is read in as source code. The effect is the same as if the entire text of the included file were inserted into the file at the location of the include statement. Upon end-of-file, source code assembly will resume from the original source file. Up to 5 levels of nesting are permitted. Up to 255 include files are allowed.

If include_file contains any spaces, it must be enclosed in quotes or angle brackets. If a fully qualified path is specified, only that path will be searched. Otherwise, the search order is:

current working directory
source file directory
MPASM assembler executable directory
 

Papabravo

Joined Feb 24, 2006
21,228
It is often the case with assemblers that "external" subroutines get assigned an address of 0, and a linkage editor that combines multiple assembly language modules may actually put a subroutine at 0 and generate code to go there.

I don't know if your assembler is an absolute assembler or a relocating assembler. When I last worked with the 16F series, MPLAB(V8.30) had an absolute assembler with no possibility of doing relocation or linking.

Scan the assembler output very carefully for warnings. Usually with errors there is no useable output, but warnings are a different story.
 

Papabravo

Joined Feb 24, 2006
21,228
So inside a single module it is not uncommon to assign a "temporary" address of 0 to all "external" addresses. These "temporary" address 0's are resolved by the linkage editor once all the modules are combined. An "unresolved external reference" could be either an error or a warning in any given compiler/assembler suite. If it was a warning and you did not get the memo then you might observe the behavior you are getting. Don't feel bad -- it has happened to me on more than one occasion.
 

be80be

Joined Jul 5, 2008
2,072
You may of hit it on the head I did some asm for 18f2550 and if I listed at the top the code it get's lost But if I include in the code where it would be used it would work fine.

I ended up rewriting my code without a bunch of includes.
 

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
Thanks for the replies fellas.

It is on a PIC18F4550 for what it's worth. I tried moving the include files that have subroutines (as opposed to just equates like the particular PIC's include file) below the ORG 0....GOTO START code, but it then it gives me errors telling me labels "START" "LOPRIORITYISR" and "HIPRIORITYISR" are not defined.

I've never seen it do that before with a label when I use a GOTO. I do in fact have a location for it to GOTO.
 

Papabravo

Joined Feb 24, 2006
21,228
Although not required by the C language standard I typically do not put code generating statements or data allocation statements in header(include) files. When using a relocatable assembler/linkage editor it might be a good idea to follow the same practice. Only put macros and symbol definitions in header files and put code in individual modules to assemble.
 

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
Although not required by the C language standard I typically do not put code generating statements or data allocation statements in header(include) files. When using a relocatable assembler/linkage editor it might be a good idea to follow the same practice. Only put macros and symbol definitions in header files and put code in individual modules to assemble.
I'm sure that's good advice. I'll try and cut and paste the files into my subroutine section and see how it behaves.

This kind of thing has motivated me to get serious (again) about learning I higher level language. Another forum pointed me to swordfish basic. It looks very easy. In the time I spend trying to do things like setup floating point routines in assembly I could of done every project I've ever wanted to do with that.
 

be80be

Joined Jul 5, 2008
2,072
Swordfish basic is good I have a full copy quit asm when I started using the 18f
But i'm glade i learn asm on the12f and 16f chips.

You can aways code in the hill and go over the asm it makes if you need faster code.
 

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
Are you planning to use the USB on the 18F4550?
I will eventually I'm sure. As my name indicates, I want to one day move beyond the whole hobbyist thing and actually get one of my invention ideas to market. A MAX-232 chip is a waste when there are uC's with built in USB functionality.

In other news, I got my floating point stuff working beautifully with PIC ASM. I can't say exactly what it was, but part of it was that I needed to move it all to the subroutine section. I did move a lot of it out of inc files and into the main asm file. I always do this..... Spend a few days wasting time on some crap with ASM that a high level would do for me, decide to learn a high level language, then I fix my ASM problems and then want to continue with that.

This time I'm actually going to make myself learn a high level language (Swordfish for now).
 

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
When you do decide to make the transition you should read Lancaster on the subject of patents and try to think more like a businessman and less like a tech weenie.

http://www.tinaja.com/glib/casagpat.pdf
That's a very interesting perspective. First, and foremost I need to be a tech weenie to get my things prototyped. I have about 5 ideas which I think are "promising," but they all require microcontrollers and other electronics to even work. One of the ideas combines a few different things to carve out the market for myself and create some brand loyalty, so I wasn't even going to attempt a patent on it.

A couple of other ideas were solutions to issues in "big industry" that I had hoped to patent and pitch to some big firms.
 

Papabravo

Joined Feb 24, 2006
21,228
Who said anything about patents?
Inventors usually have patents somewhere in the mix as they come up with good ideas. It is one approach, but it often leads to sub optimal outcomes. The actual quote that prompted my response was

"...actually get one of my invention ideas to market."

And I still think it might be the best advice he's gotten on the subject.
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,228
That's a very interesting perspective. First, and foremost I need to be a tech weenie to get my things prototyped. I have about 5 ideas which I think are "promising," but they all require microcontrollers and other electronics to even work. One of the ideas combines a few different things to carve out the market for myself and create some brand loyalty, so I wasn't even going to attempt a patent on it.

A couple of other ideas were solutions to issues in "big industry" that I had hoped to patent and pitch to some big firms.
Of course you need to be what you are, just avoid acting like an inventor as you seek to monetize your ideas. Act like a businessman and you'll go much further much faster. If you can't do that then you need to find a partner you can trust who can "think like a businessman". Trust me on this cuz I've been there and done all of that.
 
Top