This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| en:multiasm:papc:chapter_6_9 [2025/12/14 17:44] – [Pure Assembler Applications for Windows] pczekalski | en:multiasm:papc:chapter_6_9 [2025/12/14 17:58] (current) – [Pure Assembler Applications for Windows] pczekalski | ||
|---|---|---|---|
| Line 13: | Line 13: | ||
| It is possible to write an application for Windows solely in assembler. While the reason to do it is doubtful, some hints presented below, such as calling system functions, may be helpful. | It is possible to write an application for Windows solely in assembler. While the reason to do it is doubtful, some hints presented below, such as calling system functions, may be helpful. | ||
| Calls to the Windows system functions is possible via classical '' | Calls to the Windows system functions is possible via classical '' | ||
| - | A common approach to development is to start with a stub command-line C++ application and manually convert it to assembler requirements. Visual Studio Community ([[https:// | + | A common approach to development is to start with a stub command-line C++ application and manually convert it to assembler requirements. Visual Studio Community ([[https:// |
| A template of the typical pure assembler, command-line application for Windows is as follows: | A template of the typical pure assembler, command-line application for Windows is as follows: | ||
| <code asm> | <code asm> | ||
| - | .data | ||
| - | |||
| - | |||
| - | |||
| - | |||
| ... | ... | ||
| .code | .code | ||
| Line 40: | Line 35: | ||
| </ | </ | ||
| - | The name '' | + | The name '' |
| + | |||
| + | Calling system functions, such as the system message box, requires understanding the arguments passed to them. As there is no direct assembler help, documentation of the Windows system API for C++ is helpful. | ||
| + | Code below presents the necessary components of the assembler app to call system functions (library includes are configured on the project level): | ||
| + | <code adm> | ||
| + | .data | ||
| + | STD_INPUT_HANDLE = -10 | ||
| + | STD_OUTPUT_HANDLE = -11 | ||
| + | STD_ERROR_HANDLE = -12 | ||
| + | |||
| + | handler dq 0 | ||
| + | hello_msg db "Hello world", | ||
| + | info_msg | ||
| + | ... | ||
| + | includelib | ||
| + | includelib | ||
| + | EXTERN MessageBoxA: | ||
| + | ... | ||
| + | |||
| + | | ||
| + | ; RCX => _In_opt_ HWND hWnd, | ||
| + | ; RDX => _In_opt_ LPCSTR lpText, | ||
| + | ; R8 => _In_opt_ LPCSTR lpCaption, | ||
| + | ; R9 => _In_ UINT uType); | ||
| + | mov rcx, handler | ||
| + | mov rdx, offset hello_msg | ||
| + | mov r8, offset info_msg | ||
| + | mov r9, 0 ; 0 is MB_OK | ||
| + | and rsp, not 8 | ||
| + | call MessageBoxA | ||
| + | ... | ||
| + | </ | ||
| + | The majority of standard library functions accept ASCII strings and must be terminated with a 0 byte (0 is a value), so they do not require passing the string length. | ||
| + | The '' | ||
| ==== Dynamic memory management considerations ==== | ==== Dynamic memory management considerations ==== | ||
| Using dynamic memory management at the level of the assembler code is troublesome: | Using dynamic memory management at the level of the assembler code is troublesome: | ||