• Lucid Dreaming - Dream Views




    Results 1 to 9 of 9
    1. #1
      Banned
      Join Date
      Oct 2003
      Location
      Omaha, NE
      Posts
      962
      Likes
      0

      Compiling Help! Yay!

      So, I'm working on stuff (a small os). The current code is simple:
      Code:
      #include <stdio.h>
      
      char usrin[256];
      
      
      
      int main(int argc, char *argv[])
      
      {
      
       * * * *printf("> ");
      
       * * * *puts(usrin);
      
       * * * *printf("/n");
      
       * * * *printf(usrin);
      
       * * * *return 0;
      
      }
      , and to compile asm before I used c I use:
      Code:
      $ nasm myfile.asm -o myfile.bin -f bin
      But when I try to use gcc and compile it normally "
      Code:
      $ gcc myfile.c -o myfile.bin
      ", it doesn't work at all when called on my bootdisk, and gives this funky output in nix:
      Code:
      $ sh usrin.bin
      
      MZ?♥♦˙˙,@?♫▼ş♫': not found
      
      ♫▼ş♫': not found
      
      usrin.bin: 1: Syntax error: word unexpected (expecting ")")
      so then I tried to get gcc to stop before compiling, and instead just make asm code with
      Code:
      $ gcc myfile.c -o myfile.asm -S
      . That makes this code:

      Code:
       * * * *.file * "usrin.c"
      
       * * * *.def * *___main; * * * *.scl * *2; * * *.type * 32; * * .endef
      
       * * * *.text
      
      LC0:
      
       * * * *.ascii "> \0"
      
      LC1:
      
       * * * *.ascii "/n\0"
      
      .globl _main
      
       * * * *.def * *_main; *.scl * *2; * * *.type * 32; * * .endef
      
      _main:
      
       * * * *pushl * %ebp
      
       * * * *movl * *%esp, %ebp
      
       * * * *subl * *$8, %esp
      
       * * * *andl * *$-16, %esp
      
       * * * *movl * *$0, %eax
      
       * * * *movl * *%eax, -4(%ebp)
      
       * * * *movl * *-4(%ebp), %eax
      
       * * * *call * *__alloca
      
       * * * *call * *___main
      
       * * * *movl * *$LC0, (%esp)
      
       * * * *call * *_printf
      
       * * * *movl * *$_usrin, (%esp)
      
       * * * *call * *_puts
      
       * * * *movl * *$LC1, (%esp)
      
       * * * *call * *_printf
      
       * * * *movl * *$_usrin, (%esp)
      
       * * * *call * *_printf
      
       * * * *movl * *$0, %eax
      
       * * * *leave
      
       * * * *ret
      
       * * * *.comm * _usrin, 256 * * *# 256
      
       * * * *.def * *_puts; *.scl * *2; * * *.type * 32; * * .endef
      
       * * * *.def * *_printf; * * * *.scl * *2; * * *.type * 32; * * .endef
      Then I tried compiling it with nasm with
      Code:
      $ nasm myfile.asm -o myfile.bin -f bin
      . It gave me a crapload of errors, which were:

      Code:
      $ nasm myfile.asm -o myfile.bin -f bin
      
      usrin.asm:1: error: attempt to define a local label before any non-local labels
      
      usrin.asm:1: error: parser: instruction expected
      
      usrin.asm:2: error: attempt to define a local label before any non-local labels
      
      usrin.asm:2: error: parser: instruction expected
      
      usrin.asm:3: error: attempt to define a local label before any non-local labels
      
      usrin.asm:5: error: parser: instruction expected
      
      usrin.asm:7: error: parser: instruction expected
      
      usrin.asm:8: error: parser: instruction expected
      
      usrin.asm:9: error: parser: instruction expected
      
      usrin.asm:11: error: parser: instruction expected
      
      usrin.asm:12: error: parser: instruction expected
      
      usrin.asm:13: error: parser: instruction expected
      
      usrin.asm:14: error: parser: instruction expected
      
      usrin.asm:15: error: symbol `movl' redefined
      
      usrin.asm:15: error: parser: instruction expected
      
      usrin.asm:16: error: symbol `movl' redefined
      
      usrin.asm:16: error: parser: instruction expected
      
      usrin.asm:17: error: symbol `movl' redefined
      
      usrin.asm:17: error: parser: instruction expected
      
      usrin.asm:20: error: symbol `movl' redefined
      
      usrin.asm:20: error: parser: instruction expected
      
      usrin.asm:22: error: symbol `movl' redefined
      
      usrin.asm:22: error: parser: instruction expected
      
      usrin.asm:24: error: symbol `movl' redefined
      
      usrin.asm:24: error: parser: instruction expected
      
      usrin.asm:26: error: symbol `movl' redefined
      
      usrin.asm:26: error: parser: instruction expected
      
      usrin.asm:28: error: symbol `movl' redefined
      
      usrin.asm:28: error: parser: instruction expected
      
      usrin.asm:31: error: parser: instruction expected
      
      usrin.asm:32: error: parser: instruction expected
      
      usrin.asm:33: error: symbol `.def' redefined
      
      usrin.asm:33: error: parser: instruction expected
      Now, I'd have to admit I'm not the greatest at x86 assembly (that's why I'm using c ). And I'm not quite sure how to fix the errors, or otherwise get the damn thing compiled right.

      If someone out there knows what is happening, please offer some insight!

    2. #2
      moderator emeritus jacobo's Avatar
      Join Date
      Dec 2003
      Gender
      Location
      little mexico
      Posts
      2,683
      Likes
      2


      -jake
      clear eyes. strong hands.

    3. #3
      Member WerBurN's Avatar
      Join Date
      Dec 2003
      Posts
      1,051
      Likes
      5
      wheres Kaniaz when you need him? ;p

    4. #4
      Member Achievements:
      1 year registered Veteran First Class 10000 Hall Points
      Umbrasquall's Avatar
      Join Date
      Oct 2003
      Gender
      Location
      NYC
      Posts
      3,444
      Likes
      3
      I have no idea... I know some C++ and Java but what is THAT?

      Get out of the stone age?

    5. #5
      Member Stalker's Avatar
      Join Date
      Nov 2003
      Location
      Lund
      Posts
      407
      Likes
      1
      I haven't got a clue what all those errors are for (don't use the OS or compiler) but when making an OS it's usually not a very good idea to use calls that actually use another OS...
      "Trust is a weakness"
      I have a kitty. It's serial number is: 13816
      Oxeye Games

    6. #6
      Member Kaniaz's Avatar
      Join Date
      Jan 2004
      Gender
      Location
      England
      Posts
      5,441
      Likes
      9
      K. Let me look.

      [Stalker: system calls ok. linux was made "parasiting" on unix then the last final leap, the kernel, brung it all together as a last os. omg yay]

    7. #7
      Member Kaniaz's Avatar
      Join Date
      Jan 2004
      Gender
      Location
      England
      Posts
      5,441
      Likes
      9
      (Double post, yay. But life goes on.)

      Right. Where did usrin.bin come from? you compiled it as myfile.bin? Also, try renaming usrin array. Don't know why but I have a small thought tugging at the back of my brain. DO IT D:

    8. #8
      Banned
      Join Date
      Oct 2003
      Location
      Omaha, NE
      Posts
      962
      Likes
      0
      myfile.bin is the same as usrin.bin . And to make you happy I renamed the array "usrinp".

    9. #9
      Member Kaniaz's Avatar
      Join Date
      Jan 2004
      Gender
      Location
      England
      Posts
      5,441
      Likes
      9
      You see...dodgy file names, crappy variable names...

      IT CONFORMS TO ALL THE MICROSOFT STANDARDS NOW! WHY IS IT NOT WORKING?!

      Edit: Oh yes. It's not supposed to, in Microsoft standard. Go sell it for $50.

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •