Thread: Programs in memory

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Programs in memory

    Just a little question: How is the end of a program in memory signified? Or just the OS just keep tabs on where the program should start and end or something. I guess what I'm trying to ask is, is there an instruction that signifies the end of the program?

    Just curious. In my VM i'm using 0xFFFF as OP_END, just wondering how "on the mark" this kind of method is.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The OS keeps track of this internally. There is no special byte which signifies the end of a program's memory block.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Most OS's have some kind of API call to the kernel which means "end process".

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    A program is loaded into primary storage (memory) from secondary storage (disk). Bear with me here, this is 100% compewta seance!

    All files in secondary storage are well defined and thus have a beginning and an end.

    This information can also be reused in primary storage.

    And so endeth the lesson.

  5. #5
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    I'm currently using an emulator called CUSP to learn assembly. It's a very simple representation of a word-addressed processor, so it may not be accurate to modern computers in the slightest. The end of a "program" is not clearly defined really, only the end of a set of instructions, which is terminated with a HLT instruction (usually $FFFFFF in memory if your Instruction Register is 24 bits). In CUSP, there's a command that you give the assembler (.EQU @, $### where ### is the hexidecimal value of the address in memory at which your program's instructions begin) that tells it where to start executing instructions. After the instructions end, there is usually a set of variables (NOTE: there is no way to look at memory and tell what's a data value and what's an instruction). The OS probably keeps tabs on where to start the next program...

    So, to answer your question directly, it seems to me that the OS tells the computer where to start executing instructions and the program itself tells the computer where to stop executing instructions.

    Sorry if that was confusing.

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Ok I understand. I'm going to stick with what I've already got - execution starts at the beginning of the allocated memory block and ends when 0xFFFF is hit.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    DOS handled it like this: execution starts either at the address the executable was loaded to (for COM files; this was a fixed address), or at the program entry point (for EXE files), which is defined in the file header.
    The program can do whatever it wants. At some point, it will use software interrupts to call back into the operating system. With the right parameters, this call would cause the system to not return back from the system call but instead load the command interpreter command.com back into memory to replace the finished program.
    For Win32, the ExitProcess call has the same effect, except that process management works very differently.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Can we say "ret" instruction spesifies the end of the program?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    No. It's just a special jump instruction, making the program continue at a different point.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-06-2009, 12:27 PM
  2. Newbie question: pointers, other program's memory
    By xxxxme in forum C++ Programming
    Replies: 23
    Last Post: 11-25-2006, 01:00 PM
  3. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 06:45 PM
  4. Accessing memory of other programs
    By Inquirer in forum C Programming
    Replies: 4
    Last Post: 10-07-2003, 03:43 PM
  5. Accessing Video Memory Information...need help
    By KneeLess in forum C++ Programming
    Replies: 8
    Last Post: 08-24-2003, 03:53 PM