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

为什么这个汇编代码显示的数字与我指定的不同?

  •  0
  • iProgram  · 技术社区  · 7 年前

    我正在学习如何使用常量,并且已经能够将字符串和整数加载到不同的寄存器中。唯一的问题是 42 正在显示, 16777258 正在显示。这个号码一直都是一样的。如果我改变 _number 对于不同的值,我也会显示不同的数字。

      .section  __TEXT,__text,regular,pure_instructions
      .globl  _main
    _main:
      #Backup base and stack pointer
      pushq %rbp
      movq  %rsp, %rbp
    
      #Move arguments
      leaq  L_.str(%rip), %rdi
      movl  _number(%rip), %esi
      #Should calll printf("%d", 42)
      callq _printf
    
      #return 0
      xorl  %eax, %eax
    
      popq  %rbp
      retq
      .section  __TEXT,__cstring,cstring_literals
    L_.str:
      .asciz  "%d"
      _number:
      .long 42
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   iProgram    7 年前

    我要做的就是移动下面的代码

    _number:
    .long 42
    

    .section __TEXT,__cstring,cstring_literals 进入之内 .data

      .section  __TEXT,__text,regular,pure_instructions
      .globl  _main
    _main:
      #Backup base and stack pointer
      pushq %rbp
      movq  %rsp, %rbp
    
      #Move arguments
      leaq  L_.str(%rip), %rdi
      movl  _number(%rip), %esi
      #Should calll printf("%d", 42)
      callq _printf
    
      #return 0
      xorl  %eax, %eax
    
      popq  %rbp
      retq
    
      .data
      _number:
      .long 42
    
      .section  __TEXT,__cstring,cstring_literals
    L_.str:
      .asciz  "%d"