diff --git a/.gitignore b/.gitignore index 5d7b09f..55ddf45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ -a.out +*.out +*.o diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..0feabc4 --- /dev/null +++ b/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/bash + +gcc main.c -o a.out + +gcc -c main.s -o b.o +ld b.o -o b.out +rm b.o diff --git a/main.s b/main.s new file mode 100644 index 0000000..e4b4259 --- /dev/null +++ b/main.s @@ -0,0 +1,17 @@ +.global _start + +.text +_start: + movl $4, %eax # 4 (code for "write" syscall) -> EAX register + movl $1, %ebx # 1 (file descriptor for stdout) -> EBX (1st argument to syscall) + movl $msg, %ecx # 32-bit address of msg string -> ECX (2nd argument) + movl $len, %edx # length of msg string -> EDX (3rd arg) + int $0x80 # interrupt with location 0x80 (128), which invokes the kernel's system call procedure + + movl $1, %eax # 1 ("exit") -> EAX + movl $0, %ebx # 0 (with success) -> EBX + int $0x80 # see previous +.data +msg: + .ascii "Hello, world!\n" # inline ascii string + len = . - msg # assign (current address - address of msg start) to symbol "len"