hello.c, hello.S: hello world target for C compiler.

This commit is contained in:
Jan Nieuwenhuizen 2016-07-26 07:30:53 +02:00
parent f170735edb
commit 384a88dd53
4 changed files with 43 additions and 1 deletions

3
.gitignore vendored
View File

@ -12,4 +12,5 @@
/mescc.test
?
?.mes
/hello
/hello.o

View 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 $@ $^

29
hello.S Normal file
View File

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

5
hello.c Normal file
View File

@ -0,0 +1,5 @@
int main ()
{
puts ("HALLO\n");
return 0;
}