add sample hello world assembly exec
This commit is contained in:
commit
9973b9a6e9
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
hello
|
||||
*.obj
|
15
Makefile
Normal file
15
Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
.PHONY: compile link info exec
|
||||
|
||||
dyn: compile link exec
|
||||
|
||||
compile:
|
||||
as hello.s -o hello.obj
|
||||
link:
|
||||
@#ld -m elf_x86_64 --entry=main -lc --dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello hello.obj
|
||||
ld -m elf_x86_64 -o hello hello.obj
|
||||
|
||||
exec:
|
||||
@./hello
|
||||
|
||||
info:
|
||||
readelf -a hello
|
22
hello.s
Normal file
22
hello.s
Normal file
@ -0,0 +1,22 @@
|
||||
.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 New Issue
Block a user