Hi Aleko,
I agree with Tom that Dr. Carter's tutorial is a good place to start. Since it uses C to interface with the OS, we don't have to ask, "What OS?" :)
Using the "-S" switch with gcc is okay... if you're using gcc... but it isn't even close to "Nasm syntax". Open Watcom may be better... What compiler are you using now?
A tool I recently found is Agner Fog's "objconv", which Mr. Fog has recently taught Nasm syntax! It's intended for other things (converting object formats), but "objconv -fnasm myfile" (.o or executable) does a nice job of disassembling into Nasm syntax - with optimization tips in the comments!
http://www.agner.org/optimize/#objconv(output file has .asm extension - watch out you don't overwrite your source!)
Ndisasm will disassemble anything, too, of course, but it doesn't know about object/executable formats, and needs a lot more help on the command line.
You may want to look at *both* a disassembly and asm output from your compiler. "All the examples you can get" is good.
As for defining integers... when I was in school, "the integers" was an infinite set of numbers, not just the ones that can be represented in some arbitrary number of bits! When I was trying to learn C, an "int" was 16 bits, as I recall. Now, I guess "int" is 64 bits (???). In asm, we have to be more specific. ("int" in asm is an instruction, not a number)
8 bits, 1 byte - like a "char" in C... unsigned char, I guess...
mybyte db 42
or, to reserve uninitialized space:
mybyte resb 1
16 bits, 2 bytes - a "short" in C, I guess... You'll be using these a lot if you start off with "dos code". In 32-bit code, not so much.
myword dw 42
uninitialized:
myword resw 1
32 bits, 4 bytes, a "doubleword" - I guess this in "int" in 32-bit C (???)...
mydword dd 42
uninitialized:
mydword resd 1
64 bits, 8 bytes, a "quadword" - maybe this is an "int" in C, these days? Or maybe "size_t"?
myqword dq 42
uninitialized:
myqword resq 1
Nasm goes on to tword, oword, yword... that's enough to start with.
Now floats...
Single precision, 32 bits, "float" in C:
myfloat dd 1.23
the decimal point tells Nasm it's a float, not an integer
Double precision, 64 bits, "double" in C:
myfloat dq 1.23
Extended precision, 80 bits (C doesn't know this one!):
myfloat dt 1.23
A "trick" about floats... the "float" parameter to printf is always promoted to double. This is "transparent" (opaque) in C, but you'll need to know about it if you're calling printf from asm!
In asm, "for" and "if" and the like are handled by conditional jumps... Certain instructions set certain bits in the "flags register", and conditional jumps jump to a new location (or not) depending on the state of these flags. Instead of:
if (condition) do this code
we actually write:
if not (condition), jump over this code
myvar db 42
start:
mov al, [myvar]
top:
cmp al, 42
je got_it ; jump if equal
; what to do if we didn't find it
; probably don't want to "fall through" to the "yes" code
jmp done
got_it:
; what to do if we found it
done:
; exit your program
push 0
call ExitProcess
or
mov eax, 1
int 80h
or
mov ah, 4Ch
int 21h
(Nasm will let you use 0xABCD to indicate hexidecimal numbers, like C. I prefer 0ABCDh)
This is apparently a hard concept for some people to "get", but to me it seems much more intuitive than "if", "while", "for" and such. Macros are available to generate code for "if" and all, but learn what it "really does" first...
Tell us what OS you're using, and maybe we can provide more concrete examples...
Best,
Frank