Author Topic: whats wrong with "mov al, [sp+2]"  (Read 16481 times)

sancho111180

  • Guest
whats wrong with "mov al, [sp+2]"
« 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

nobody

  • Guest
Re: whats wrong with "mov al, [sp+2]"
« Reply #1 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