0

I have done my fair share of searching the web and I cant seem to find a satisfactory answer to this question. Yes, I see answers like it means contents of an such.. however, what I can't seem to wrap around my head is the following

Suppose I declare a var to hold a string value "Hi my name is jeff" and I want to print it out to the screen.

var1: db "Hi my name is jeff",0
len equ $-var1

mov eax, 4
mov ebx, 1
mov ecx, var1
mov edx, len
int 80h

Following the logic of the square brackets the above code should not be printing out the "contents" of the variable byte by byte, but the addresses of the variable byte by btye incremented.

I am just trying to learn assembly and have found myself asking questions similar to this or when I should put square brackets or not.. More likely then not I have just tested it and if its giving me a wrong output I put square brackets around it. I would like to actually understand when to use and when not to use it

Edward Lim
  • 713
  • 7
  • 29
  • 2
    By the way, the NASM documentation as pdf gives plenty of information. You should get familiar with this source first, maybe, this helps You clarify a lot, before even going out and ask google or SO. – icbytes Oct 25 '16 at 07:35
  • 1
    _"Following the logic of the square brackets the above code should not be printing out the "contents" of the variable byte by byte, but the addresses of the variable"_ No, it should not, because [`sys_write` expects a `const char*` (i.e. the address of a string) in `ecx`](http://www.informatik.htw-dresden.de/~beck/ASM/syscall_list.html). – Michael Oct 25 '16 at 08:21
  • _"when I should put square brackets or not"_ That depends on the context in which you're going to use the value. Sometimes you want the address, and sometimes you want whatever is stored at that address. – Michael Oct 25 '16 at 08:25
  • 1
    Do you understand pointers in C? In NASM, `[]` always means a memory operand, and without `[]` always means an immediate or register operand. – Peter Cordes Oct 25 '16 at 08:53
  • thanks for the link with the duplication of question! I didnt come accross that at all while googling and its very helpful! Probably had the wrong keywords – Edward Lim Oct 25 '16 at 20:18

0 Answers0