🚧 Adds assembly hello world

This commit is contained in:
Daniel Svitan 2025-05-05 21:43:27 +02:00
parent 07d45752cc
commit 0d144f025d
3 changed files with 26 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea/
a.out
*.out
*.o

7
build.sh Executable file
View File

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

17
main.s Normal file
View File

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