hello.c, hello.S: hello world target for C compiler.
authorJan Nieuwenhuizen <janneke@gnu.org>
Tue, 26 Jul 2016 05:30:53 +0000 (07:30 +0200)
committerJan Nieuwenhuizen <janneke@gnu.org>
Tue, 26 Jul 2016 05:30:53 +0000 (07:30 +0200)
.gitignore
GNUmakefile
hello.S [new file with mode: 0644]
hello.c [new file with mode: 0644]

index 991e838d51c663da56c70137ad8e294ce3d45c81..dc0185ba541b2f9ca85f8bd35ba25b8ee7673fea 100644 (file)
@@ -12,4 +12,5 @@
 /mescc.test
 ?
 ?.mes
-
+/hello
+/hello.o
index 81c685e62b85baa6ec76858517869b43af96adca..e7e1ca672e96d8afd4912950540bfe95afa385f3 100644 (file)
@@ -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 (file)
index 0000000..36c42e0
--- /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 (file)
index 0000000..6eafe71
--- /dev/null
+++ b/hello.c
@@ -0,0 +1,5 @@
+int main ()
+{
+  puts ("HALLO\n");
+  return 0;
+}