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!
Bookmarks