Thread: org statement

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    2

    org statement

    I am having trouble setting where I want the program to start in memory. I have a boot block on my pic and in assembly language I would use the org = 0x00800 command. How is this done in C?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There is no standard for an org statement in C, as C is a portable language.

    One common way to perform an "org" statement in C is to use linker commands. But it is not always the way, so you will have to look up the documentation for your compiler.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why do you need to select where the program is placed in memory anyway?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    2

    boot block

    The PIC I am using has a boot block from 0x00000 to 0x007FF. A program is not recognized unless I start it at 0x00800.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Look into the startup code in your system.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    Quote Originally Posted by Elysia View Post
    Why do you need to select where the program is placed in memory anyway?
    Do you not grasp the concept of an embedded platform or what?

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by brewbuck View Post
    Do you not grasp the concept of an embedded platform or what?
    Nope, never programmed for an embedded device.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Actually, it doesn't matter if it's an embedded device or not - it will still be located someplace. It's just a matter of whether it is located in a SPECIFIC place, or a generic place. For example, the code starts at (around) 0x400000 in Windows executables. It doesn't have to be exactly there, it's just one of the arbitrary choices, and I'm sure we can make the linker produce a starting address somewhere different - but we don't care much about it for regular executables. DLL's is a slightly different matter, as there are often multiple DLL's loaded in the same process, so we don't want all of those to sit in the same space, as that means they have to be relocated. So each DLL will have it's own base-address [if they are well designed, that is].

    But of course, when you are working on low-level systems, with no virtual memory management, the location of code, data, heap and stack becomes every so much more noticable.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 07:18 AM
  3. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM