Hi,
I'm beginning assembly on FreeBSD and tried a simple HelloWorld. I'm using 2 separate files, one for some macro and defines, one for the actual code (looks a long post but hang on, it's just hello world =D )
Here is the macro file :
And here is the program itself :
I assembled it with NASM using the following commands :
Here are my questions :
1/ As you can see I'm using ELF64. If I try with ELF instead I get an error from the linker (on the second command) that says:
So what if I want 32 bits assembly?
2/ As you can see in my program, the files to assemble are not in the same directory as NASM. I'd like to put that on some environment variable (...a bit like on *cough* Windows *cough*...) so I don't have to specify the whole path every time.
3/ When I launch the program... nothing happens... no Hello World displayed =(
Any hint?
I'm beginning assembly on FreeBSD and tried a simple HelloWorld. I'm using 2 separate files, one for some macro and defines, one for the actual code (looks a long post but hang on, it's just hello world =D )
Here is the macro file :
Code:
;
; system.inc : aliases definitions (defines & macros)
;
; File descriptors
%define stdin 0
%define stdout 1
%define stderr 2
; symbolic names for syscalls
%define SYS_nosys 0
%define SYS_exit 1
%define SYS_fork 2
%define SYS_read 3
%define SYS_write 4
; Add a short, non-global procedure with a long name, so we do not accidentally reuse the name in our code
section .text
align 4
access.the.bsd.kernel:
int 80h
ret
; syscall number macro
%macro system 1
mov eax, %1
call access.the.bsd.kernel
%endmacro
; syscall macros
%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
And here is the program itself :
Code:
;
; helloWorld.asm
;
%include '/usr/home/fgauthier/Documents/Dev/system.inc'
section .data
hello db 'hello, World!', 0Ah
helloLength equ hello
section .text
global _start
_start :
push dword helloLength
push dword hello
push dword stdout
sys.write
push dword 0
sys.exit
I assembled it with NASM using the following commands :
# nasm -f elf64 /usr/home/fgauthier/Documents/Dev/helloWorld.asm
# ld -s -o /usr/home/fgauthier/Documents/Dev/helloWorld /usr/home/fgauthier/Documents/Dev/helloWorld.o
Here are my questions :
1/ As you can see I'm using ELF64. If I try with ELF instead I get an error from the linker (on the second command) that says:
Code:
ld: i386 architecture of input file `/usr/home/fgauthier/Documents/Dev/helloWorld.o' is incompatible with i386:x86-64 output
2/ As you can see in my program, the files to assemble are not in the same directory as NASM. I'd like to put that on some environment variable (...a bit like on *cough* Windows *cough*...) so I don't have to specify the whole path every time.
3/ When I launch the program... nothing happens... no Hello World displayed =(
Any hint?