-1

Assume a byte has been defined in the data segment

DSEG      SEGMENT
    NUM   DB   ?
DSEG      ENDS

Then, what is the meaning of the following instructions in terms of addressing mode?

LEA     SI, NUM

and

MOV     NUM, 1AH

Since NUM is a label for a memory entry (say 1000H), I assume that the first one is interpreted as MOV SI, [1000] and the second is interpreted as MOV [1000], 1AH. So, they use direct memory addressing mode. Am I right?

mahmood
  • 23,197
  • 49
  • 147
  • 242
  • `LEA` loads the address of the operand, not the value stored there. – Bo Persson Oct 16 '16 at 18:06
  • So the address is `[10000]` in this case. Isn't that? – mahmood Oct 16 '16 at 18:13
  • `10000H` is more than 16 bits and you are using 16 bit x86 so you are wrong! – GJ. Oct 16 '16 at 20:03
  • Excuse me... I missed something.... Since the address in `[]` is a logical address is is 16bit wide, e.g. [1000H]. I edited the post. – mahmood Oct 17 '16 at 06:40
  • In Intel syntax those should be `lea si,[num]` and `mov [num],1Ah`. There're some assemblers which will work even with syntax you used in question, but I dislike them (and they can compile the official Intel syntax too, so there's no reason to not use the `[]`). After you follow official Intel syntax, `lea` is the only exception where using `[]` doesn't mean accessing memory, only address calculation. – Ped7g Oct 17 '16 at 11:25
  • I'm not sure what you mean with "direct" addressing... Whatever is enclosed in `[]` is calculated to some number, which is used as an address to access particular byte/word/dword/qword in memory. Inside the brackets can be just fixed immediate (address), or register, or some limited expression like `[ebx + esi*2 + NumArray]`. Anything without `[]` should be just value without accessing memory (but your assembler is trying to be smarter and will fill-in `[]` in some cases for you). In NASM the `mov si,NUM` will load `si` with the value of symbol `NUM` i.e. address of that byte = equal to `lea`. – Ped7g Oct 17 '16 at 11:30

1 Answers1

2

Nope, not quite.

The LEA is used to move the address into the destination. So, the address represented by the label NUM is moved into SI. This is immediate mode, since you are directly moving a value into a register.

The second one, while it doesn't have a byte ptr or [], moves the value 0x1a into the memory location represented by the label NUM. This is direct mode since you are using a raw memory address represented by NUM.

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67
  • Do you mean that `lea` is using immediate addressing and the second one uses direct mode? – mahmood Oct 16 '16 at 19:29
  • 1
    Not really. LEA doesn't really move data, it just figures out addresses and offsets, allowing you to do some simple mathematics quickly. Have a look at my answer to this question: http://stackoverflow.com/questions/1658294/whats-the-purpose-of-the-lea-instruction – David Hoelzer Oct 16 '16 at 19:35
  • The second is using direct addressing. – David Hoelzer Oct 16 '16 at 19:35
  • But don't both instructions technically use direct addressing mode? Only that `lea` doesn't load anything from memory but only stores the effective address and `mov` actually loads something. – cadaniluk Oct 16 '16 at 20:23
  • 1
    No. The value of `NUM` in that instruction in machine language will be a static value. There is no actual reference to memory, so it would be wrong to think of it as direct addressing. – David Hoelzer Oct 16 '16 at 23:11
  • Assemble it and then use GDB or ndisasm to dump it out or view it with hexdump. – David Hoelzer Oct 16 '16 at 23:12
  • @David Hoelzer: That `lea` should be immediate addressing mode... because you are moving a `number` or `value` to a register. No matter, who is providing the value (programmer or OS), it is neither register mode nor memory mode. Do you agree with that? – mahmood Oct 17 '16 at 06:52
  • Ah, good point Mahmood. I edited to clarify the immediate vs the direct. He threw me when he asked, "...using immediate *addressing* mode..." – David Hoelzer Oct 17 '16 at 10:49