Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux x86程序集打印问题_Linux_Assembly_X86 - Fatal编程技术网

Linux x86程序集打印问题

Linux x86程序集打印问题,linux,assembly,x86,Linux,Assembly,X86,我写这篇文章是为了在x86中打印argv[0]: .section .data newline: .int 0xa, 0 .section .text .globl _start _start: sub %al, %al movl 4(%esp), %edi /* Pointer to argv[0]. */ sub %ecx, %ecx /* Set %ecx to 0.*/ not %ecx

我写这篇文章是为了在x86中打印
argv[0]

.section .data
    newline: .int 0xa, 0

.section .text
    .globl _start
    _start:
        sub %al, %al
        movl 4(%esp), %edi /* Pointer to argv[0]. */
        sub %ecx, %ecx    /* Set %ecx to 0.*/
        not %ecx          /* Set %ecx to -1.*/
        repne scasb       /* Search for %al over and over.*/
        not %ecx          /* Set %ecx to |%ecx| - 1.*/
        dec %ecx
        movl %ecx, %edx   /* Move the strlen of argv[0] into %edx.*/

        movl $4, %eax
        movl $1, %ebx
        movl 4(%esp), %ecx
        int $0x80

        movl $newline, %ecx
        movl $1, %edx
        int $0x80

        movl $1, %eax
        movl $0, %ebx
        int $0x80
当我运行此文件(“打印”)时,输出如下:

[08:27 assembly]$ ./print test
./print[08:30 assembly]$ 
test
[08:33 assembly]$
当我通过gdb运行这个时,edx中保存的实际字符串长度是27,它检查的字符串是“/home/robert/assembly/print”,而不是“/print”。因此,我将
%esp
偏移量更改为8,以检查
argv[1]
。使用与前面相同的命令,输出如下:

[08:27 assembly]$ ./print test
./print[08:30 assembly]$ 
test
[08:33 assembly]$
为什么检查
argv[0]
会导致奇怪的输出,而
argv[1]
却如预期的那样?

我认为gdb通过添加到
argv[0]
的完整路径来“帮助”您。打印后,
%eax
保存打印的字符数,因此您需要再次为
系统重新加载%eax以打印
$newline
%ebx
应该还可以)-幸运的是,“test”是正确的长度。天知道你用那根更长的绳子得到了什么样的系统调用


我得说你做得很好!(在您尝试打印它之前,最好先检查一下
argc
以确保
argv[1]
在那里)。

啊,我想知道调用
sys\u write
后,
%eax
是否被修改了,但我不确定该在哪里查找此类内容。不过,在重新加载后,它可以正常工作!