NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: mgoppold on August 19, 2013, 03:20:42 PM

Title: invalid effective address error
Post by: mgoppold 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
Title: Re: invalid effective address error
Post by: Frank Kotler 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

Title: Re: invalid effective address error
Post by: mgoppold on August 19, 2013, 04:07:27 PM
Thanks!