News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Some basic Win32 questions for assembly programmers

Started by NoCforMe, January 25, 2024, 12:42:14 PM

Previous topic - Next topic

sinsi

DF = direction flag

QuoteThis is the state on arriving at start:
For that particular build of Windows :biggrin:
🍺🍺🍺

daydreamer

Because data? Zeroes out,you can save x bytes of zeroed array (s) bloat using data section
Is fp and xmm registers also contains values or zeroed when start of program
Createthread can specify bigger stack space than standard 1MB, is that also possible when start program with create process from another program?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

sinsi

Quote from: daydreamer on January 26, 2024, 12:56:21 AMCreatethread can specify bigger stack space than standard 1MB, is that also possible when start program with create process from another program?
The stack size and commit is set by the linker in the PE header, so you can't set it.
Apparently, there is no way of knowing what it is (there are no Windows APIs to query).
🍺🍺🍺

jj2007

#18
Quote from: sinsi on January 26, 2024, 02:31:18 AMThe stack size and commit is set by the linker in the PE header, so you can't set it.

At build time, linker option /stack:200000 would set the stack size. How to do that from CreateThread is another story:

HANDLE CreateThread(
  [in, optional]  LPSECURITY_ATTRIBUTES   lpThreadAttributes,
  [in]            SIZE_T                  dwStackSize,
  [in]            LPTHREAD_START_ROUTINE  lpStartAddress,
  [in, optional]  __drv_aliasesMem LPVOID lpParameter,
  [in]            DWORD                   dwCreationFlags,
  [out, optional] LPDWORD                 lpThreadId
);

daydreamer

I am curious about createthread use big stack space for local arrays might memory alloc under the hood vs thread alloc memory in beginning of thread takes same time ?

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

NoCforMe

#20
I'd like to post one note in case any beginning Win32 programmers are reading this.

Regarding saving and restoring the "sacred" (i.e., non-volatile) registers (EBX, ESI, EDI, EBP): it's been established that you don't need to worry about saving and restoring these registers in the immediate startup code (your code immediately after your "start" label which is the first code executed when the program is loaded). But you need to preserve them anywhere else in your code.

However, my suggestion is that you always save and restore these registers if you use them as a safe programming practice. Later on you can choose not to do this in places where it's not necessary, but to start, get in the habit of preserving them:
    PUSH    EBX
    MOV     EBX, OFFSET MyStruct
    CMP     [EBX].someMember, 1
    JE      somewhere    ;Make sure "somewhere" is before the POP EBX.
    ...
    POP     EBX
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on January 26, 2024, 07:38:29 AManywhere else in your code

Actually, you should preserve esi edi ebx in callbacks (WndProc is the most important one). We had a thread 11 years ago: Preservation of esi, edi, ebx in general code

Now that raises an interesting point: in a GUI application, is there any code that is not under the hat of the WndProc?

NoCforMe

You're technically correct. However, for the sake of Win32 n00bs, I'm going to stick to my recommendation to always preserve these registers as a good safe programming habit to get into.
Assembly language programming should be fun. That's why I do it.

daydreamer

Note about vcc using inline-asm warning about need to preserve ebx

When you do many recursive call proc, for example x10, you can estimate (local arrays + register pushes+ return adress) *10 = needed stack space
If it exceeds current stack space do I get gp fault?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

Quote from: daydreamer on January 27, 2024, 05:24:56 PMIf it exceeds current stack space do I get gp fault?

You get the stack overflow error.