The following code works as expected, printing "Hello".
.section .data
string:
.ascii "Hello, World!\n\0"
.section .text
.globl _start
_start:
mov $5, %rdx # num characters to print
mov $string, %rcx # address of string to print
mov $1, %rbx # print to stdout
mov $4, %rax # print syscall
int $0x80
mov $1, %rax # exit syscall
int $0x80
I'm making a one-line change in an attempt to print the first few characters of argv[0]
, which should be the name of the program (ex: "/home/sam/Documents/print"). However, nothing actually seems to print. Why is this the case?
.section .data
string:
.ascii "Hello, World!\n\0"
.section .text
.globl _start
_start:
mov $5, %rdx # num characters to print
mov 8(%rsp), %rcx # <-- attempt to print argv[0]
mov $1, %rbx # print to stdout
mov $4, %rax # print syscall
int $0x80
mov $1, %rax # exit syscall
int $0x80
When I attempt to debug in gdb it appears that the rcx register has the correct address of the string.
x/s $rcx // 0x7fffffffe37f: "/home/sam/Documents/print"
EDITED
Code updated and works as expected.
.section .text
.globl _start
_start:
movq $1, %rax # print syscall
movq $1, %rdi # print to stdout
movq 8(%rsp), %rsi # <-- attempt to print argv[0]
movq $5, %rdx # num characters to print
syscall
movq $60, %rax # exit syscall
syscall