Lysergiks
Lysergiks

Reputation: 11

Segment ignored in effective address with nasm

I am trying to write a simple bootloader in x86 assembly using nasm. At several places in the code, I have to use an effective address of the form [es:di]. The code compiles without error, but at run time, the segment is ignored. For instance, for

mov ax, 0x07C0
mov es, ax
mov di, 0x10
lea eax, [es:di]

Right after the lea, the registers look like :

EAX=00000010 
EDI=00000010
ES =07c0 00007c00 0000ffff 00009300

But EAX should have been 7C10. The problem occurs at any point of the program (including when nothing has been done before), and the program runs in real mode.

My question is: is this normal? Am I missing something? How can I fix this?

Upvotes: 1

Views: 247

Answers (1)

Michael
Michael

Reputation: 58437

Intel's manual may not be super clear on this. Or it may not be obvious where to look, at least. But if you read section 7.3.16.1 (Address Computation Instruction), it says:

The LEA (load effective address) instruction computes the effective address in memory (offset within a segment) of a source operand and places it in a general-purpose register.

So, yes, I'd say that your result is the expected one.

Upvotes: 4

Related Questions