22

I'm working on a more indepth hello world using NASM following this tutorial (section 4). This tutorial essentially teaches you how to handle command line input.
This is the snippet of the code in question:

section .text
        global _start

_start:
        pop     ebx     ; arg count
        pop     ebx     ; arg[0] the program name
        pop     ebx     ; arg[1-n] the remainder of the args
                        ; must each be indiviually popped

The code errors out during compilation with error: instruction not supported in 64-bit mode referring to the 3 pop instructions above. Upon viewing the docs it seems that this code only works for 32-bit systems.

Is there a 64-bit pop instruction? Does anyone have a 64 bit tutorial using pop that I can look at?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
ahodder
  • 11,353
  • 14
  • 71
  • 114
  • 5
    You do realize the tutorial is for 32-bit? I believe you can generate 32-bit code by setting the output format to `elf32` rather than `elf`, which should allow you to follow this tutorial even on a 64-bit machine... – Chris Dodd Jun 08 '12 at 18:21
  • 2
    @Aedin - Yes, you should stay in 32-bit mode if following that tutorial. Not only are the register names different when using 64 bits, so are also the calling conventions. Just replacing the `pop`'s is unlikely to work. – Bo Persson Jun 09 '12 at 10:40

2 Answers2

26

Yes, the 64-bit pop instruction is... POP. :-) You need to use it against 64-bit registers though (like rbx).

Brian Knoblauch
  • 20,639
  • 15
  • 57
  • 92
  • When I replaced with `POP.`, getting this error: "_error: parser: instruction expected_" I'm using `nasm -f elf64 myfile.asm` myfile includes this line: `POP. eax;` – hasany Jan 23 '21 at 11:50
  • @hasany Remove the "." as it is causing a syntax error. It should just be "POP EAX" – Brian Knoblauch Jan 23 '21 at 14:27
  • @hasany You may have a syntax error before that instruction then. Or perhaps you are missing a required assembler directive. I'd recommend opening you own question on this site, with the minimum source code required to cause the error included. – Brian Knoblauch Jan 24 '21 at 19:55
-1

basically you can convert it into 64bit by replacing eax to rax (same goes for all other registers)

Niyas Ali
  • 203
  • 2
  • 9