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?
The PUSH/POP instructions POP retrieves the value from the top of the stack and stores it into the destination, then increments the SP register (by 2). PUSH and POP can be used to save and restore the values of registers when the register needs to be used for some other function temporarily.
The pop instruction removes the 4-byte data element from the top of the hardware-supported stack into the specified operand (i.e. register or memory location). It first moves the 4 bytes located at memory location [SP] into the specified register or memory location, and then increments SP by 4. Syntax. pop <reg32>
You can use push and pop to save registers at the start and end of your function. For example, "rbp" is a preserved register, so you need to save its value before you can use it: push rbp ; save old copy of this register. mov rbp,23. mov rax,rbp. pop rbp ; restore main's copy from the stack.
Stack is amount of program (RAM) memory normally allocated at the top of CPU memory heap and grow (at PUSH instruction the stack pointer is decreased) in opposite direction. A standard term for inserting into stack is PUSH and for remove from stack is POP.
Yes, the 64-bit pop
instruction is... POP. :-) You need to use it against 64-bit registers though (like rbx
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With