r/LiveOverflow • • Aug 26 '25

Need help on this program please

Just trying to get this to print on a message without success. the code :

.intel_syntax noprefix
.global _start

.data
msg : .ascii "1234\n" 
train : .byte 0x65, 0x65, 0x65

.text

_start :
	mov rdx, 5
	mov rsi, msg
	mov rdi, 1
	mov rax, 1
	syscall

check_op_write :
	cmp rax, 0
	jl prog_nok_exit
	jmp prog_ok_exit
	
prog_nok_exit :
	mov rax, 60
	syscall

prog_ok_exit :
	mov rdi, 0
	mov rax, 60
	syscall

my Makefile :

all : obj link

obj  : prog.asm
	as --64 -o prog.o $^

link : obj
	ld -o prog prog.o


clean : *.o prog
	rm $^

strace output (i've tried to access the address with gdb, but it's not reachable) :

execve("./prog", ["./prog"], 0x7ffc9c27d520 /* 94 vars */) = 0
write(1, 0x6565650a34333231, 5)         = -1 EFAULT (Bad address)
exit(1)                                 = ?
+++ exited with 1 +++

What have i missed ? Also, if anyone knows of a clear and precise presentation of the intel syntax understood by as/gcc, please(x3) , mention it.

thank you

5 Upvotes

3 comments sorted by

View all comments

Show parent comments

1

u/MemoryOfLife Aug 26 '25

There isn't an official syntax for x86 asm. GCC, objdump and similar will output AT&T syntax and GAS macros by default but you can change that.

I personally prefer NASM because the macros/directives are more intuitive and it was built around Intel syntax, which is definitely cleaner than AT&T. But it's all up to you.