NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: sancho111180 on July 10, 2007, 09:20:35 PM

Title: whats wrong with "mov al, [sp+2]"
Post by: sancho111180 on July 10, 2007, 09:20:35 PM
hi
i am trying to write a little bit of boot code with nasm, i know there are lots of examples around, but i want to write it on my own..first thing i stumbled over was the following

begin

BITS 16
...
mov al, [sp+2]

end


why do i geterror: invalid effective address here? if i replace [sp+2] with [esp+2] it works, but in real mode esp sure doesnt make much sense! can anyone enlighten me?

thanks

martin
Title: Re: whats wrong with "mov al, [sp+2]"
Post by: nobody on July 10, 2007, 11:11:54 PM
Welcome to 16-bit addressing modes! :) Using 16-bit instructions, you've got bx, si, di, and bp to work with. bx and bp are "base" registers (bp defaults to ss:bp), si and di are "index" registers. You can have one of each, plus an offset. That's it.

You can do:

mov bp, sp
mov al, [bp + 2]

Or... you can probably "ASSume" that the upper part of esp is clear - or clear it - and use esp. Using bp makes for shorter code, so probably "mov bp, sp" is better(?).

Best,
Frank