I was looking at this sample code
GLOBAL DllMain
EXPORT DllMain
GLOBAL myFuncX1
EXPORT myFuncX1
GLOBAL myFuncX2
EXPORT myFuncX2
section .code use32
..start:
DllMain: ; This code is required in .dll files
mov eax,1
ret 12
myFuncX1:
; FUNCTION #1
; A- passed parameters:
; required: value#1 , value#2
;
; example:
; push dword [0x500]
; push dword [0x010]
; call [myFuncX1]
;
; B- this function returns:
; EAX= value#1 + value#2
push ebp
mov ebp, esp
mov eax, dword [ebp+08] ; eax=value#1
mov ecx, dword [ebp+12] ; ecx=value#2
.
.
.
.
.
etc
(this is a truncated copy of the sample code found at
http://forum.nasm.us/index.php?topic=1652.0 )
I was wondering a few things.
On the entry point for DllMain I notice that not only is it set to GLOBAL like the entrypoint function in EXE files, but also it is exported. Does the entrypoint function in a DLL file really need to be exported? What if it's not going to be called from another program?
I then noticed something else. Other functions like myFuncX1 and myFuncX2 that are going to be exported not only have the compiler directive EXPORT, but they also use GLOBAL. Isn't GLOBAL only required on an entrypoint function? And I also noticed the exact structure of the entrypoint function. It contains the code:
mov eax,1
ret 12
This leaves me with 2 questions.
1) Why does it need to set EAX (the register that holds the return-value of a function) to 1? If you aren't going to be using the entrypoint function in your programming, do you really need to set EAX to a specific value?
2) Why is "ret 12" needed? Having a number after the "ret" opcode is only needed if you need to skip a specific number of bytes in the stack when returning. I don't think there's anything on the stack, unless your function put something there. In EXE files, I've been able to use just "ret" without any number. Why is it needed for DLL files?