x86 Assembly pushl/popl don't work with “Error: suffix or operands invalid”

后端 未结 5 719
逝去的感伤
逝去的感伤 2020-11-29 01:45

I\'m a newbie to assembly programming, working through Programming Ground Up on an Ubuntu x86_64 desktop with GNU assembler v2.20.1.

I\'ve been able to assemble/link

5条回答
  •  遥遥无期
    2020-11-29 02:35

    You need to replace the push/pop sequence with

    pushq $1       # push the value 1 onto the stack
    popq %rax      # pop 1 off the stack and into the %eax register
    

    Note the error message is "suffix or operand invalid", you only checked the second part of the logical OR in the error message, maybe because you weren't exactly sure what the suffix means: it's the "l".

    Edit: Please see Thomas answer for an explanation why your code won't work anyway even if it assembles.

提交回复
热议问题