linking to assembly

This is a discussion on linking to assembly within the C Programming forums, part of the General Programming Boards category; Sorry, I have no way to reproducve your problem, and I'm too busy/lazy to get a TC compiler to see ...

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Sorry, I have no way to reproducve your problem, and I'm too busy/lazy to get a TC compiler to see what it generates. Are you using small or large memory model?

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

  2. #17
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Use a debugger, put a breakpoint on main and then single step it until it looks like its about to go very very wrong.
    Then adjust your code to take this into account.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #18
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    I worked out all my problems with the functions, but i still need to find a way to make a flat binary image out of my c program. Can anyone tell me what i need to do to make a DOS 16 bit binary loadable at startup?

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by xixpsychoxix View Post
    I worked out all my problems with the functions, but i still need to find a way to make a flat binary image out of my c program. Can anyone tell me what i need to do to make a DOS 16 bit binary loadable at startup?
    Well, you need something that is compatible with your boot sector. Unfortunately, each OS has it's own boot sector.

    You may want to take an existing boot-loader, and then use the tools in the boot-loader to load your OS. Grub for example can load a "module" or "kernel" in a certain format that there are grub documentation on how that should be done.

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

  5. #20
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #21
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    Does anyone know of a simple bootloader that will be able to load a DOS 16 bit binary? I have no clue how to write one that will work. After i load the file into memory, given that i loaded the program at segment = a offset = b, i should just push a, push b, and retf to run the code, right? or is it more complicated than that with a DOS binary?

  7. #22
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    ok, does anyone happen to know how to get gcc to output a flat binary? I tried compiling as such:

    gcc -c program.c
    ld program.o -o program.bin --oformat=binary --Ttext=0x0

    this told me that I could not perform PE operations on non-PE file program.bin. I also tried this:

    gcc -c program.c
    ld -o test.bin -Ttext 0x0 -e _main test.o

    This gave me the error:
    Undefined reference to _alloca
    Undefined reference to __main

    How do i specify the command line options to make the binary image? Also, if i cant use gcc, how can i use g++ to make the binary image?
    Last edited by xixpsychoxix; 07-16-2008 at 06:32 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking C++ and Assembly
    By Warlax in forum C++ Programming
    Replies: 6
    Last Post: 10-19-2007, 04:33 PM
  2. HELP: assembly & C linking woes....
    By andrewwan1980 in forum Tech Board
    Replies: 4
    Last Post: 09-28-2007, 04:17 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 03:28 AM
  4. Linking an assembly routine into a GCC project
    By huh in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2002, 02:14 PM
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 02:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21