165042b18Sopenharmony_ci 1 ; nasm -f elf hello.asm # this will produce hello.o ELF object file 265042b18Sopenharmony_ci 2 ; ld -s -o hello hello.o # this will produce hello executable 365042b18Sopenharmony_ci 3 465042b18Sopenharmony_ci 4 section .text 565042b18Sopenharmony_ci 5 global _start ;must be declared for linker (ld) 665042b18Sopenharmony_ci 6 765042b18Sopenharmony_ci 7 _start: ;tell linker entry point 865042b18Sopenharmony_ci 8 965042b18Sopenharmony_ci 9 00000000 BA0E000000 mov edx,len ;message length 1065042b18Sopenharmony_ci 10 00000005 B9[00000000] mov ecx,msg ;message to write 1165042b18Sopenharmony_ci 11 0000000A BB01000000 mov ebx,1 ;file descriptor (stdout) 1265042b18Sopenharmony_ci 12 0000000F B804000000 mov eax,4 ;system call number (sys_write) 1365042b18Sopenharmony_ci 13 00000014 CD80 int 0x80 ;call kernel 1465042b18Sopenharmony_ci 14 1565042b18Sopenharmony_ci 15 00000016 B801000000 mov eax,1 ;system call number (sys_exit) 1665042b18Sopenharmony_ci 16 0000001B CD80 int 0x80 ;call kernel 1765042b18Sopenharmony_ci 17 1865042b18Sopenharmony_ci 18 section .data 1965042b18Sopenharmony_ci 19 2065042b18Sopenharmony_ci 20 00000000 48656C6C6F2C20776F- msg db 'Hello, world!',0xa ;our dear string 2165042b18Sopenharmony_ci 21 00000009 726C64210A 2265042b18Sopenharmony_ci 22 len equ $ - msg ;length of our dear string 2365042b18Sopenharmony_ci 23 24