Took a sample program from https://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86-first-program.html and put the code into these files.
This into hello.asm:
And this into system.inc
Compiled (changing format to elf64 as that would match the system's architecture):
That does not print Hello World. What am I doing wrong?
This into hello.asm:
Code:
%include 'system.inc'
section .data
hello db 'Hello, World!', 0Ah
hbytes equ $-hello
section .text
global _start
_start:
push dword hbytes
push dword hello
push dword stdout
sys.write
push dword 0
sys.exit
Code:
%define stdin 0
%define stdout 1
%define stderr 2
%define SYS_nosys 0
%define SYS_exit 1
%define SYS_fork 2
%define SYS_read 3
%define SYS_write 4
section .text
align 4
access.the.bsd.kernel:
int 80h
ret
%macro system 1
mov eax, %1
call access.the.bsd.kernel
%endmacro
%macro sys.exit 0
system SYS_exit
%endmacro
%macro sys.fork 0
system SYS_fork
%endmacro
%macro sys.read 0
system SYS_read
%endmacro
%macro sys.write 0
system SYS_write
%endmacro
Code:
% nasm -f elf64 hello.asm
% ld -s -o hello hello.o