hello sir GoneFishing;
I can suppose that thats happening when you're linking the file or maybe an environment variable.
When I have started on linux I received many segmentation fault, I suppose that's because rsp register is not aligned before a call.
rsp=???????????????0
I can guess that happens if using 32 bits instead of 64 bits values (like printing an decimal interger instead of unsigned qword).
man 2 intro
man 2 syscall
man 2 syscalls
man 2 _syscall
You can try compile with gcc to have sure. I'm now on linux, so I can put more info.
I'm a hobbyst, don't expect much, but we can join forces, I can do some tests on this side if you need.
I linked with ld and with gcc this time, I try things with ld only but If I will release some software I will compile with gcc (exception handling).
If you need know whats happening behind the scene do a "-v" (verbose) on gcc comand line, this helped me to know how to use ld while trying a gtk samples using jwasm
I have used objdump -x on a generated file while reading gtk2 manual, because I do not know whats macro and whats functions.
um.asm
section "text" alias ".text" class_code
section "data" alias ".data" class_data
.USE64
stdout equ 1
sys_write equ 1
sys_exit equ 60
.data
msg_01 db 10,"Hello world",10
msg_len equ $-msg_01
.text
.entry _start
_start:
mov rdx,msg_len
mov rsi,offset msg_01
mov rdi,stdout
mov rax,sys_write
syscall
mov rdi,39
mov rax, sys_exit
syscall
mineiro@assembly:~/Assembly/solasm$ sol32 um.asm um.o -elf64
Solar Assembler version 0.36.12
Copyright (c) 2007,2012 Bogdan Valentin Ontanu, All rights reserved.
Build on 2012_11_5 at 21:44:54
Assembling file: um.asm
Assembler pass: 1
Assembler pass: 2
Assembler lines: 97
Output bytes : 750
Assembler time: 11 ms
-----------------------------
:~/Assembly/solasm$ file um.o
um.o: ELF 64-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
:~/Assembly/solasm$ head --bytes=18 um.o > start
:~/Assembly/solasm$ echo -e "\x3e" > middle
:~/Assembly/solasm$ head --bytes=1 middle > middle1
:~/Assembly/solasm$ tail --bytes=+20 um.o > end
:~/Assembly/solasm$ cat start middle1 end > um.o
:~/Assembly/solasm$ file um.o
um.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
:~/Assembly/solasm$ ld -m elf_x86_64 um.o -o um
:~/Assembly/solasm$ ./um ;echo $?
Hello world
39
:~/Assembly/solasm$ rm start
:~/Assembly/solasm$ rm middle
:~/Assembly/solasm$ rm middle1
:~/Assembly/solasm$ rm end
:~/Assembly/solasm$ gcc -nostartfiles um.o ; ./a.out ; echo $?
Hello world
39
:~/Assembly/solasm$ gcc -s -nostartfiles um.o ; ./a.out ; echo $?
:~/Assembly/solasm$ rm um.o
---------------------------------------------------------------------------------
man exit
different calling convention from native to library C functions, .
dois.asm
section "text" alias ".text" class_code
section "data" alias ".data" class_data
.USE64
extern exit
extern puts
extern printf
.entry _start
.data
msg db "hello world",10,0
msg_len equ $-msg
msg_fmt db 10,'message: %d %d %d %d %d %d %d %d %d %d %d %d %d',10,0
.text
_start:
push 15
push 14
push 13
push 12
push 11
push 10
push 9
push 8
mov r9,7
mov r8,6
mov rcx,5
mov rdx,4
mov rsi,3
mov rdi,offset msg_fmt
call printf
add rsp,8*8
mov rdi,msg
call puts
mov rdi,57
call exit
dois.sh
sol32 dois.asm dois.o -elf64
head --bytes=18 dois.o > start
echo -e "\x3e" > middle
head --bytes=1 middle > middle1
tail --bytes=+20 dois.o > end
cat start middle1 end > dois.o
ld -m elf_x86_64 -dynamic-linker /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 -L/lib/x86_64-linux-gnu -lc -o dois dois.o
rm start
rm middle
rm middle1
rm end
./dois ; echo $?
:~/Assembly/solasm$ ./dois.sh
Solar Assembler version 0.36.12
Copyright (c) 2007,2012 Bogdan Valentin Ontanu, All rights reserved.
Build on 2012_11_5 at 21:44:54
Assembling file: dois.asm
Assembler pass: 1
Assembler pass: 2
Assembler lines: 42
Output bytes : 1041
Assembler time: 10 ms
-----------------------------
message: 3 4 5 6 7 8 9 10 11 12 13 14 15
hello world
57
:~/Assembly/solasm$ gcc -nostartfiles dois.o ; ./a.out ; echo $?
message: 3 4 5 6 7 8 9 10 11 12 13 14 15
hello world
57
:~/Assembly/solasm$ ld -m elf_x86_64 -dynamic-linker /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 -L/lib/x86_64-linux-gnu -lc -o dois dois.o
:~/Assembly/solasm$ ./a.out ; echo $?
message: 3 4 5 6 7 8 9 10 11 12 13 14 15
hello world
57
:~/Assembly/solasm$
but look this, give to me errors
:~/Assembly/solasm$ ld -m elf_x86_64 -dynamic-linker -I/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 -L/lib/x86_64-linux-gnu -lc -o dois dois.o
:~/Assembly/solasm$ ./a.out ; echo $?
bash: ./a.out: Arquivo ou diretório não encontrado (like a file or folder not found) <-- Is this whats happening to you?
127
:~/Assembly/solasm$ ld -nostartfiles -m elf_x86_64 -dynamic-linker /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 -L/lib/x86_64-linux-gnu -lc -o dois dois.o
dois.o: na função `_start': <-- Is this whats happening to you?
(.text+0x4d): referência indefinida para `printf' (reference to printf not found) <-- Is this whats happening to you?
dois.o: na função `_start':
(.text+0x60): referência indefinida para `puts' (reference to puts not found)
dois.o: na função `_start':
(.text+0x6f): referência indefinida para `exit' (reference to exit not found)
:~/Assembly/solasm$ gcc -nostartfiles -dynamic-linker dois.o ; ./a.out ; echo $?
message: 3 4 5 6 7 8 9 10 11 12 13 14 15
hello world
57
:~/Assembly/solasm$
-------------edited------------
I have done an error, sub rsp,8*8 instead of add rsp,8*8, I corrected example above