代码之家  ›  专栏  ›  技术社区  ›  McLovin

装配和标准件中的fprintf

  •  0
  • McLovin  · 技术社区  · 5 年前

    我正在打电话 fputs(str, stdout); 从装配。

    我为什么要这么做 push dword [stdout] push stdout ?

    fputs(str, *stdout) ,为什么我们要取消引用 stdout 装配中?

    extern fputs
    extern stdout
    
    section .data
        hw: db "Hello World!", 10, 0
    
    section .text
        global main
    
    main:
        enter 0,0
    
        push dword [stdout]
        ;push stdout
        push hw
        call fputs
    
        leave
        mov eax, 0
        ret
    
    0 回复  |  直到 5 年前
        1
  •  6
  •   Peter Cordes    5 年前

    你正在取消对asm标签的引用 stdout ,相当于 &stdout 在C。它是内存中的静态位置 FILE* 已存储。

    只有C数组类型的行为类似于asm标签,其中C中的名称是地址,而不是内容。

    另请参见 Why in NASM do we have to use square brackets ([ ]) to MOV to memory location?


    .

    (除了真正的C数组,其中裸名称是第一个元素的地址。)


    在C中,具有自动存储类的变量(即本地变量)也可以有名称,而不仅仅是静态的。在asm中,符号只能放在静态地址上(C中的自动存储通常是x86 asm中的寄存器,或类似堆栈空间的寄存器 [ebp - 8] 如果您需要溢出/重新加载。堆栈地址不是链接时间常数,因此不能有标签。可以相对于ESP或EBP寻址堆栈。)