Reputation:
Every time I try to compile my code with NASM, where there is a "pop" ("pop al" in this case), it gives me an error.
20: error: invalid combination of opcode and operands
In line 20, I have
pop al
What's the problem?
Upvotes: 0
Views: 466
Reputation: 16596
The problem is literally the error message provided by the assembler: "invalid combination of opcode and operands". The POP
instruction has no POP r8
encoding possible. In other words, you cannot pop an 8-bit value off the stack
The closest equivalent would be pop ax
, which uses a POP r16
encoding to pop a 16-bit value off the stack into the ax
register. However, this is not exactly the same as your code, because it will modify both the lower 8-bit half (al
) and the upper 8-bit half (ah
) of the 16-bit ax
register.
Another alternative is to load the value directly from the stack, using something like mov al, BYTE PTR [(r/e)sp]
. Because this does not alter the stack pointer, you will need to adjust it manually.
Next time, please also specify what your target platform is. This is important, because the 16-bit real mode has very limited possibilities for addressing modes, compared to 32-bit and 64-bit protected mode. If you don't specify which mode you're targeting, the answers you get may not work for you. Like here, I have no idea whether that mov
instruction should use rsp
(64-bit), esp
(32-bit), or sp
(16-bit).
Upvotes: 6