I have problems accessing the command line of a process from a 64-bit Linux build program. To reproduce this with minimal code, I made this 32-bit program that prints the first 5 characters of the program name:
.section .text
.globl _start
_start:
movl% esp,% ebp
movl $ 4,% eax # write
movl $ 1,% ebx # stdout
movl 4 (% ebp),% ecx # program name address (argv [0])
movl $ 5,% edx # hard-coded length
int $ 0x80
movl $ 1,% eax
movl $ 0,% ebx
int $ 0x80
This program works. When I translate it to 64 bit and run on Linux 64, it doesn't print anything:
.section .text
.globl _start
_start:
movq% rsp,% rbp
movq $ 4,% rax
movq $ 1,% rbx
movq 8 (% rbp),% rcx # program name address?
movq $ 5,% rdx
int $ 0x80
movq $ 1,% rax
movq $ 0,% rbx
int $ 0x80
Where is my mistake?
source share