diff --git a/.gitignore b/.gitignore index 991e838d..dc0185ba 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ /mescc.test ? ?.mes - +/hello +/hello.o diff --git a/GNUmakefile b/GNUmakefile index 81c685e6..e7e1ca67 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -100,3 +100,10 @@ mescc.test: lib/lalr.scm c-lexer.scm mescc.scm guile-mescc: mescc.test cat main.c | guile -s $^ + +hello.o: hello.S + as --32 -march=i386 -o $@ $^ + +hello: hello.o + ld -A i386 -m elf_i386 -nostdlib -nodefaultlibs -A i386 -o $@ $^ +# ld -A i386 -m elf_i386 -A i386 -o $@ $^ diff --git a/hello.S b/hello.S new file mode 100644 index 00000000..36c42e01 --- /dev/null +++ b/hello.S @@ -0,0 +1,29 @@ + +.text # section declaration + + # we must export the entry point to the ELF linker or + .global _start # loader. They conventionally recognize _start as their + # entry point. Use ld -e foo to override the default. + +_start: + + # write our string to stdout + + movl $len,%edx # third argument: message length + movl $msg,%ecx # second argument: pointer to message to write + movl $1,%ebx # first argument: file handle (stdout) + movl $4,%eax # system call number (sys_write) + int $0x80 # call kernel + + # and exit + + movl $0,%ebx # first argument: exit code + movl $1,%eax # system call number (sys_exit) + int $0x80 # call kernel + +.data # section declaration + +msg: + .ascii "Hello, world!\n" # our dear string + len = . - msg # length of our dear string + diff --git a/hello.c b/hello.c new file mode 100644 index 00000000..6eafe713 --- /dev/null +++ b/hello.c @@ -0,0 +1,5 @@ +int main () +{ + puts ("HALLO\n"); + return 0; +}