I'm new to this forum. I have a little experience with high-level languages (really little). Nearly one month ago I thought it would be a good idea to see how assembly worked so after choosing nasm (IA-32) on linux I started learning from a tutorial.
Now, after ending it, I tried to write a simple program where you get the computer to print a list of 100 number (1 2 4 8 16...) but I couldn't even get it right. I get this output:
1PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP(continues)...
The program is this:
section .text
    global main
main:
    mov word [num], '1'
    mov ecx, 100
doubl:
    push ecx ; to push the loop counter
    mov eax, 4
    mov ebx, 1
    mov ecx, num
    mov edx, 1
    int 0x80
    sub ecx, 30h
    add ecx, ecx   ; shl ecx, 1
    add ecx, 30h
    mov [num], ecx   ; deleting this line I get  11111111111111111...
    pop ecx  ; to pop the loop counter
    loop doubl
exit:
    mov eax, 1
    int 0x80    
section .bss
num resw 2
It looks like the error is in the part that doubles the number or the one that stores it in the variable 'num', yet I don't understand why it happens and how to solve it.
By the way can someone explain me when to use the square brackets exactly? Is there a rule or something? The tutorial calls it "effective address" and it looks like I have to use the brackets when I want to move (or do something with) the content of a variable instead of doing it to the variable's address. Yet I'm quite confused about it. I see it used in:
mov ebx, count
inc word [ebx]
mov esi, value
dec byte [esi]
But isn't it obvious that one wants to increment the content of the register (since it doesn't have an address (or does it?) ??
 
     
    