hello.c, hello.S: hello world target for C compiler.
This commit is contained in:
parent
f170735edb
commit
384a88dd53
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -12,4 +12,5 @@
|
|||
/mescc.test
|
||||
?
|
||||
?.mes
|
||||
|
||||
/hello
|
||||
/hello.o
|
||||
|
|
|
@ -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
29
hello.S
Normal 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
|
||||
|
Loading…
Reference in a new issue