.section .data # .equ slash, 0x2f #slash: .ascii "/" #slash: .ascix "/" slash: .byte 0x2f .section .bss .lcomm cwd_len, 4 # used to store pwd's len .lcomm bin_len, 4 # used to store binary's name lenght .lcomm addr, 4 # aux, for testing .section .text .globl _start _start: nop # let gdb stop in here if needed movl %esp, %ebp # save stack pointer, just in case movl 4(%esp), %eax # give eax argv[0]'s value xorl $1, %ebx # set ebx to one movl 8(%esp, %ebx, 4), %edi # move %ebx before any command line value subl %eax, %edi # (command line lenght\0)+1 should be in %edi now dec %edi # get rid of the null separator movl %edi, cwd_len # save cwd's real lenght movl (%esp, %ebx, 4), %ecx # now, move to to the end of argv[0] find: sub $slash, %ecx # don't really know if this working as expected jg exit # exit if found dec %ecx # decrement %ecx inc %ebx # inrement %ebx cmp %eax, %ecx # bail out if cwd's len is traspassed je exit jmp find exit: movl $1, %eax int $0x80