0

from my previous doubt - Difference between “mov eax, [num]” and “mov eax, num”

I came to know " mov eax, num " will store address of num in eax and " mov eax, [num] " will store value of num in eax

Now HERE !

    mov     edx, strLen     ; Arg three: the length of the string
    mov     ecx, str        ; Arg two: the address of the string
    mov     ebx, 1          ; Arg one: file descriptor, in this case stdout
    mov     eax, 4          ; Syscall number, in this case the write(2)  

    int     0x80            ; Interrupt 0x80   

section .data     
    str:     db 'Hello, world!',0xA
    strLen:  equ $-str

Ideally edx register should have length, so

  • as " mov ecx, str " - stores address of str in ecx
  • haven't " mov edx, strlen " should also store address of strlen and not the value in edx.
  • to store value of strlen in edx, why are we not using " mov edx, [strlen] "

the following code is referenced from this link - http://asm.sourceforge.net/intro/hello.html

Its killing me !

Thanks in Advance...

Community
  • 1
  • 1
Sham
  • 71
  • 1
  • 1
  • 5
  • is the declaration in section .data and not in section .bss has any relevance to my question ! PS : I know section .data, is for declaring constants and section .bss, is for declaring variables. – Sham Feb 22 '16 at 15:16
  • *"mov eax, [num] " will store value **of** num in eax"* is probably more accurately stated as, *"mov eax, [num] " will store value **at** num in eax"*, which is probably what you meant. – lurker Feb 22 '16 at 16:26
  • @lurker yes Lurker thats what I meant – Sham Feb 22 '16 at 18:42

1 Answers1

1

strLen is an equate (strLen: equ $-str). So what's happening is just compile-time textual substitution from mov edx, strLen to mov edx, 14.

Using brackets here would be incorrect, because that would give you mov edx, [14], which isn't what you want to do.

(see section 3.2.4 EQU: Defining Constants in the NASM manual)

Michael
  • 57,169
  • 9
  • 80
  • 125
  • @Micheal hey Micheal thanks for this but how about following ! "file_name" below is not an equate section .data **file_name db 'myfile.txt'** section .text mov eax, 8 mov ebx, **file_name** mov ecx, 0777 int 0x80 – Sham Feb 22 '16 at 18:43
  • There you're loading the address of `file_name`, as the question you linked to explained. – Michael Feb 22 '16 at 20:24