Program jumping into include file on start

Discussion in 'Embedded Systems and Microcontrollers' started by wannaBinventor, Feb 5, 2011.

  1. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    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: Feb 5, 2011
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Is this assembler?

    If so why are you punishing yourself? Why not just use C? The 18F is designed for C.
     
  3. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    I don't really know C. Perhaps one day I will, but for now I want to keep writing assembly.
     
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016

    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.
     
  5. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    You no there two ways to handle include files But thats a book so maybe this will help
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    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.
     
  7. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    You can do both now absolute assembler and relocation or linking.
     
  8. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    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.
     
  9. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    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.
     
  10. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    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.
     
  11. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    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.
     
  12. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    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.
     
  13. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    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.
     
  14. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Are you planning to use the USB on the 18F4550?
     
  15. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    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).
     
  16. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    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
     
  17. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Who said anything about patents?
     
  18. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    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.
     
  19. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    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: Feb 8, 2011
  20. Papabravo

    Expert

    Feb 24, 2006
    10,152
    1,793
    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.
     
Loading...