1

i am totally confused about addressing modes in nasm x86 assembly language.
after reading nasm manual i found that [ ] is used to get the value at the memory location specified inside square brackets.

my understanding:

var db 10

mov eax , var     ;  address of var is copied into eax register
mov eax , [var]   ;  value of var 10 is copied into eax register

here the part i get confused :

here the screenshot of the below code from a book i read

MY_TABLE TIMES 10 DW 0    ; Allocates 10 words (2 bytes) each initialized to 0
MOV EBX, [MY_TABLE]       ; Effective Address of MY_TABLE in EBX
MOV [EBX], 110            ; MY_TABLE[0] = 110
ADD EBX, 2                ; EBX = EBX +2
MOV [EBX], 123            ; MY_TABLE[1] = 123

( this code is taken from assembly_tutorial tutorialspoint.com )

in the second line MOV EBX, [MY_TABLE] , according to my understanding MY_TABLE points to a address that is initialized to zero. so it should move the value 0 to the ebx register. but they mentioned in comment that effective address of MY_TABLE is copied into EBX register. my doubt is that why does it copy the address instead of the value zero.

in the third line MOV [EBX], 110 , according to their comment ebx has effective address of MY_TABLE . so according to my understanding [ EBX ] should get the value at the address , so it becomes mov value_at_effective_address , 110 . so what is the point of copying a constant into a value?

 MOV EBX, [MY_TABLE] ;a value copied into ebx or a address copied into ebx?

 MOV [EBX], 110  ; moving 110 to a memory loation or to a value at a memory address.

 MOV [EBX], 123 ; moving 123 to a memory location or to a value at a momory address.
  • 1
    Either they meant `lea ebx, [my_table]` (most likely, given that it mentions "effective addresses" ; `lea` is short for "load effective address", and uses memory operands, but doesn't really dereference anything, it just does arithmetic), or `mov ebx, my_table`, or the tutorial is meant for another assembler. BTW I wouldn't really trust anything from tutorialspoint.com. – Matteo Italia Nov 29 '17 at 06:40
  • 2
    Are you sure that the tutorial really says that `mov ebx, [my_table]` loads the address of my_table into ebx? If so, find a new tutorial. Either one of the following would load the address of my_table into ebx: `mov ebx, my_table` or `lea ebx, [my_table]`. – prl Nov 29 '17 at 06:41
  • @prl i attached the screenshot of the page. –  Nov 29 '17 at 06:46
  • In case it wasn't clear, I was serious about getting a different tutorial. It's hard to learn when you can't trust what you're reading. I suppose it's possible you've encountered the one error, but not likely. – prl Nov 29 '17 at 07:12
  • 2
    Tutorial Point has a lot of mistakes. This one is a recurring one here on SO that has been discussed before. The tutorial is wrong and it should have been LEA. – Michael Petch Nov 29 '17 at 07:15

0 Answers0