mov reg16, [sp]  doesn't work!!

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Neptune

mov reg16, [sp]  doesn't work!!

Post by Neptune »

I can't figure this out. All I need to do is mov the contents of sp into a register, but nasm complains 'invalid effective address'. I've tried it with every single register combination, but it won't let me do it. Please help!
Khumba

RE:mov reg16, [sp]  doesn't work!!

Post by Khumba »

If you want to move the address SP points to into a register, use "mov reg16, sp".  You can't use [sp], because x86 assembly removed that in order to have a plain [offset] addressing mode.  So you'll have to load SP into another register (BX, BP, SI, or DI) and use that instead.
Khumba

RE:mov reg16, [sp]  doesn't work!!

Post by Khumba »

Actually, there's no [bp] mode either, only [bp+offset], but good compilers (like nasm) translate this to [bp+0].
Neptune

RE:mov reg16, [sp]  doesn't work!!

Post by Neptune »

Thank you!
Post Reply