Author Topic: invalid effective address error  (Read 3071 times)

Offline mgoppold

  • Jr. Member
  • *
  • Posts: 2
invalid effective address error
« on: August 19, 2013, 03:20:42 PM »
I get this error output when I try to assemble a BIN file.  What is the problem?
Code: [Select]
boot.s:18: error: invalid effective address
boot.s:19: error: invalid effective address

Here's the command to compile the file.
Code: [Select]
nasm -f bin -o boot.bin boot.s

Here's the file, "boot.s".
Code: [Select]
BITS 16

section .text

org 0x7c00
jmp 0:start

start:
mov ax, 0
mov ss, ax

mov ax, 0x4000
mov sp, ax

sub sp, 32

mov ax, 1
mov [sp], ax  ;ERROR HERE
mov [sp+2], ax  ;ERROR HERE

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2286
  • Country: us
Re: invalid effective address error
« Reply #1 on: August 19, 2013, 03:51:35 PM »
Valid 16-bit addresses consist of an optional offset, an optional base register (bx or bp), and an optional index register (si or di). That's it! "[sp]" is not on that list.

32-bit addresses can use any GP register as a base register, and any but esp as an index register. It also allows an optional scale (2, 4, or 8 ) to be multiplied by the index register.

Even in 16-bit code, you can use 32-bit addressing modes. "[esp]" would be "legal" and would "probably" work, although it might be wise to be sure that the upper bits are zero.

Best,
Frank


Offline mgoppold

  • Jr. Member
  • *
  • Posts: 2
Re: invalid effective address error
« Reply #2 on: August 19, 2013, 04:07:27 PM »
Thanks!