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
Assembly 在x86 asm中输出变量值_Assembly_X86_Output - Fatal编程技术网

Assembly 在x86 asm中输出变量值

Assembly 在x86 asm中输出变量值,assembly,x86,output,Assembly,X86,Output,我正在汇编中编写一个程序,但它不起作用,所以我想在x86函数中输出变量,以确保这些值是我期望的值。有没有一种简单的方法可以做到这一点,还是非常复杂 如果这样做更简单,那么汇编函数将从C函数中使用,并使用gcc进行编译。您的问题似乎是“如何在x86汇编程序中打印变量值”。x86本身不知道如何做到这一点,因为它完全取决于您使用的输出设备(以及操作系统提供的该输出设备接口的细节) 一种方法是使用操作系统系统调用,正如您在另一个答案中提到的那样。如果您在x86 Linux上,那么可以使用sys\u wr

我正在汇编中编写一个程序,但它不起作用,所以我想在x86函数中输出变量,以确保这些值是我期望的值。有没有一种简单的方法可以做到这一点,还是非常复杂


如果这样做更简单,那么汇编函数将从C函数中使用,并使用gcc进行编译。

您的问题似乎是“如何在x86汇编程序中打印变量值”。x86本身不知道如何做到这一点,因为它完全取决于您使用的输出设备(以及操作系统提供的该输出设备接口的细节)

一种方法是使用操作系统系统调用,正如您在另一个答案中提到的那样。如果您在x86 Linux上,那么可以使用
sys\u write
sys调用将字符串写入标准输出,如下所示(GNU汇编程序语法):

但是,如果您想要打印数值,那么最灵活的方法是使用C标准库中的
printf()
函数(您提到您正在从C调用汇编程序Rounties,因此您可能仍然链接到标准库)。这是一个例子:

int_format:
    .string "%d\n"

.globl asmfunc2
    .type asmfunc2, @function

asmfunc2:
    movl $123456, %eax

    # print content of %eax as decimal integer
    pusha           # save all registers
    pushl %eax
    pushl $int_format
    call printf
    add $8, %esp    # remove arguments from stack
    popa            # restore saved registers

    ret
有两点需要注意:

  • 您需要保存和恢复寄存器,因为它们会被调用破坏;及
  • 调用函数时,参数按从右到左的顺序排列

这正是我想要的,非常感谢您的帮助。
int_format:
    .string "%d\n"

.globl asmfunc2
    .type asmfunc2, @function

asmfunc2:
    movl $123456, %eax

    # print content of %eax as decimal integer
    pusha           # save all registers
    pushl %eax
    pushl $int_format
    call printf
    add $8, %esp    # remove arguments from stack
    popa            # restore saved registers

    ret