News:

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

Main Menu

Something You May Not Know About the Macro

Started by LiaoMi, July 21, 2016, 07:34:49 PM

Previous topic - Next topic

LiaoMi

Hallo,

there is an interesting article about macros Something You May Not Know About the Macro in MASM Assembly Language Programming http://www.codeproject.com/Articles/1080585/Something-You-May-Not-Know-About-the-Macro-in-MASM , Can this really be used for a possible debugging?

Regards

jj2007

Quote from: LiaoMi on July 21, 2016, 07:34:49 PMCan this really be used for a possible debugging?

Sure. Here is the typical output produced by echo in a debugging session of a very simple Windows application:** Start J:\Masm32\MasmBasic\Res\bldallRM.bat
***** user-defined OPT_xx variables: ***
**** 64-bit assembly ****
OPT_Arg1:
OPT_Arg2:
OPT_Out:  "Skel6432GUI_4Prologue64.exe"
OPT_Res:  Skel6432GUI_4Prologue


*** Assemble, link and run Skel6432GUI_4Prologue ***

*** Assemble using \masm32\bin\ml64 /c  /Fo "Skel6432GUI_4Prologue" tmp_file.asm ***
Assembling: tmp_file.asm
*** using Res\JBasic64.lib ***
** 64-bit assembly **
------------------------------
####### txApi0 equ ap0$ db ??000E+1, "GetStdHandle", 0 was undefined ######
CALL GetStdHandle as 0/1
####### txApi1 equ ap1$ db ??0022+1, "lstrlenA", 0 was undefined ######
push rcx
CALL lstrlenA as 1/2
####### txApi2 equ ap2$ db ??0036+1, "WriteFile", 0 was undefined ######
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/3
CALL GetStdHandle as 0/3
push rcx
CALL lstrlenA as 1/3
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/3
CALL GetStdHandle as 0/3
push rcx
CALL lstrlenA as 1/3
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/3
push r9
push rdx
push rcx
CALL WriteFile as 2/3
CALL GetStdHandle as 0/3
push rcx
CALL lstrlenA as 1/3
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/3
push r9
push rdx
push rcx
CALL WriteFile as 2/3
[rcx] - check for Real4 conversion??
####### txApi3 equ ap3$ db ??0134+1, "sprintf", 0 was undefined ######
push r8
push rdx
push rcx
CALL sprintf as 3/4
CALL GetStdHandle as 0/4
push rcx
CALL lstrlenA as 1/4
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/4
push r9
push rdx
push rcx
CALL WriteFile as 2/4
####### txApi4 equ ap4$ db ??019A+1, "Sleep", 0 was undefined ######
CALL Sleep as 4/5
WinMain has 0 arguments in 0 bytes
[j@WinMain]
/-1:s *********************************
## PROLOGUE: WinMain: args+locals=08H+030H=56, _flags=010H, _userparms=
------------
## Prolog WinMain: sub rsp, 64 ##
CALL GetStdHandle as 0/5
push rcx
CALL lstrlenA as 1/5
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/5
[rax] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/5
CALL GetStdHandle as 0/5
push rcx
CALL lstrlenA as 1/5
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/5
push r9
push rdx
push rcx
CALL WriteFile as 2/5
CALL GetStdHandle as 0/5
push rcx
CALL lstrlenA as 1/5
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/5
push r9
push rdx
push rcx
CALL WriteFile as 2/5
CALL GetStdHandle as 0/5
push rcx
CALL lstrlenA as 1/5
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/5
push r9
push rdx
push rcx
CALL WriteFile as 2/5
[rcx] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/5
CALL GetStdHandle as 0/5
push rcx
CALL lstrlenA as 1/5
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/5
push r9
push rdx
push rcx
CALL WriteFile as 2/5
####### txApi5 equ ap5$ db ??036F+1, "GetModuleHandleA", 0 was undefined ######
CALL GetModuleHandleA as 5/6
####### txApi6 equ ap6$ db ??0383+1, "LoadIconA", 0 was undefined ######
push rcx
CALL LoadIconA as 6/7
[rax] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/7
CALL GetStdHandle as 0/7
push rcx
CALL lstrlenA as 1/7
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/7
CALL GetStdHandle as 0/7
push rcx
CALL lstrlenA as 1/7
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/7
####### txApi7 equ ap7$ db ??042C+1, "LoadCursorA", 0 was undefined ######
CALL LoadCursorA as 7/8
[rax] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/8
CALL GetStdHandle as 0/8
push rcx
CALL lstrlenA as 1/8
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/8
CALL GetStdHandle as 0/8
push rcx
CALL lstrlenA as 1/8
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/8
CALL GetStdHandle as 0/8
push rcx
CALL lstrlenA as 1/8
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/8
####### txApi8 equ ap8$ db ??0514+1, "SetLastError", 0 was undefined ######
CALL SetLastError as 8/9
####### txApi9 equ ap9$ db ??0528+1, "RegisterClassExA", 0 was undefined ######
push rcx
CALL RegisterClassExA as 9/10
[rax] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/10
CALL GetStdHandle as 0/10
push rcx
CALL lstrlenA as 1/10
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/10
####### txApi10 equ ap10$ db ??0593+1, "GetLastError", 0 was undefined ######
CALL GetLastError as 10/11
####### txApi11 equ ap11$ db ??05A7+1, "FormatMessageA", 0 was undefined ######
push r10
push r10
push r9
push r8
push rdx
CALL FormatMessageA as 11/12
CALL GetStdHandle as 0/12
push rcx
CALL lstrlenA as 1/12
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/12
CALL GetStdHandle as 0/12
push rcx
CALL lstrlenA as 1/12
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/12
####### txApi12 equ ap12$ db ??0638+1, "LoadMenuA", 0 was undefined ######
push rcx
CALL LoadMenuA as 12/13
[rax] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/13
CALL GetStdHandle as 0/13
push rcx
CALL lstrlenA as 1/13
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/13
CALL GetStdHandle as 0/13
push rcx
CALL lstrlenA as 1/13
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/13
CALL GetStdHandle as 0/13
push rcx
CALL lstrlenA as 1/13
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/13
push r9
push rdx
push rcx
CALL WriteFile as 2/13
####### txApi13 equ ap13$ db ??0734+1, "CreateWindowExA", 0 was undefined ######
push r10
push r10
push r8
push rdx
CALL CreateWindowExA as 13/14
[rcx] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/14
CALL GetStdHandle as 0/14
push rcx
CALL lstrlenA as 1/14
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/14
CALL GetStdHandle as 0/14
push rcx
CALL lstrlenA as 1/14
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/14
push r9
push rdx
push rcx
CALL WriteFile as 2/14
CALL GetStdHandle as 0/14
push rcx
CALL lstrlenA as 1/14
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/14
CALL GetLastError as 10/14
push r10
push r10
push r9
push r8
push rdx
CALL FormatMessageA as 11/14
CALL GetStdHandle as 0/14
push rcx
CALL lstrlenA as 1/14
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/14
CALL GetStdHandle as 0/14
push rcx
CALL lstrlenA as 1/14
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/14
####### txApi14 equ ap14$ db ??08D6+1, "GetMessageA", 0 was undefined ######
push rcx
CALL GetMessageA as 14/15
####### txApi15 equ ap15$ db ??08EA+1, "TranslateMessage", 0 was undefined ######
push rcx
CALL TranslateMessage as 15/16
####### txApi16 equ ap16$ db ??08FE+1, "DispatchMessageA", 0 was undefined ######
push rcx
CALL DispatchMessageA as 16/17
####### txApi17 equ ap17$ db ??0912+1, "ExitProcess", 0 was undefined ######
push rcx
CALL ExitProcess as 17/18
WndProc has 4 arguments in 32 bytes
[j@WndProc]
/-1:s1111 *********************************
## PROLOGUE: WndProc: args+locals=028H+050H=120, _flags=010H, _userparms=cb
push rsi
push rdi
push rbx
push rcx
------------
## Prolog WndProc: sub rsp, 96 ##
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
[rax] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
push r9
push rdx
push rcx
CALL WriteFile as 2/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
push r9
push rdx
push rcx
CALL WriteFile as 2/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
[rax] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
push r9
push rdx
push rcx
CALL WriteFile as 2/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
[uMsg] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
push r9
push rdx
push rcx
CALL WriteFile as 2/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
[hWnd] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
[rbx] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
push r10
push r10
push rdx
CALL CreateWindowExA as 13/18
[hEdit] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
CALL GetLastError as 10/18
push r10
push r10
push r9
push r8
push rdx
CALL FormatMessageA as 11/18
CALL GetStdHandle as 0/18
push rcx
CALL lstrlenA as 1/18
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/18
####### txApi18 equ ap18$ db ??0DB7+1, "SendMessageA", 0 was undefined ######
push rcx
CALL SendMessageA as 18/19
####### txApi19 equ ap19$ db ??0DCB+1, "GetStockObject", 0 was undefined ######
CALL GetStockObject as 19/20
push r8
push rcx
CALL SendMessageA as 18/20
####### txApi20 equ ap20$ db ??0DF3+1, "SetFocus", 0 was undefined ######
push rcx
CALL SetFocus as 20/21
CALL GetStdHandle as 0/21
push rcx
CALL lstrlenA as 1/21
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/21
####### txApi21 equ ap21$ db ??0E46+1, "InvalidateRect", 0 was undefined ######
push rcx
CALL InvalidateRect as 21/22
[rcx] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/22
CALL GetStdHandle as 0/22
push rcx
CALL lstrlenA as 1/22
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/22
push r9
push rdx
push rcx
CALL WriteFile as 2/22
CALL GetStdHandle as 0/22
push rcx
CALL lstrlenA as 1/22
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/22
CALL GetStdHandle as 0/22
push rcx
CALL lstrlenA as 1/22
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/22
CALL GetStdHandle as 0/22
push rcx
CALL lstrlenA as 1/22
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/22
####### txApi22 equ ap22$ db ??0F82+1, "BeginPaint", 0 was undefined ######
push rdx
push rcx
CALL BeginPaint as 22/23
CALL GetStdHandle as 0/23
push rcx
CALL lstrlenA as 1/23
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/23
####### txApi23 equ ap23$ db ??0FD5+1, "SetTextColor", 0 was undefined ######
push rcx
CALL SetTextColor as 23/24
####### txApi24 equ ap24$ db ??0FE9+1, "SetBkColor", 0 was undefined ######
push rcx
CALL SetBkColor as 24/25
####### txApi25 equ ap25$ db ??0FFE+1, "TextOutA", 0 was undefined ######
push r9
push rcx
CALL TextOutA as 25/26
[lastMenu] - check for Real4 conversion??
push r8
push rdx
push rcx
CALL sprintf as 3/26
push r10
push r9
push rcx
CALL TextOutA as 25/26
####### txApi26 equ ap26$ db ??103E+1, "EndPaint", 0 was undefined ######
push rdx
push rcx
CALL EndPaint as 26/27
CALL GetStdHandle as 0/27
push rcx
CALL lstrlenA as 1/27
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/27
push r9
push rdx
push rcx
CALL WriteFile as 2/27
####### txApi27 equ ap27$ db ??10A5+1, "MoveWindow", 0 was undefined ######
push r10
push r9
push rcx
CALL MoveWindow as 27/28
CALL GetStdHandle as 0/28
push rcx
CALL lstrlenA as 1/28
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/28
push r9
push rdx
push rcx
CALL WriteFile as 2/28
CALL GetStdHandle as 0/28
push rcx
CALL lstrlenA as 1/28
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/28
push r9
push rdx
push rcx
CALL WriteFile as 2/28
push rcx
CALL SendMessageA as 18/28
####### txApi28 equ ap28$ db ??1173+1, "PostQuitMessage", 0 was undefined ######
CALL PostQuitMessage as 28/29
[hWnd,uMsg,wParam,lParam] - check for Real4 conversion??
??1180 db "DefWinProc: %x, %x, %x, %x",13,10, 0
push r10
push r10
push r9
push r8
push rdx
push rcx
CALL sprintf as 3/29
CALL GetStdHandle as 0/29
push rcx
CALL lstrlenA as 1/29
push r9
push r8
push rdx
push rcx
CALL WriteFile as 2/29
####### txApi29 equ ap29$ db ??11E4+1, "DefWindowProcA", 0 was undefined ######
push r9
push r8
push rdx
push rcx
CALL DefWindowProcA as 29/30
pop rcx
pop rbx
pop rdi
pop rsi
## Epilog WndProc: add rsp, 104 ##
### init db "kernel32", 0
### init db "msvcrt", 0
### init db "user32", 0
### init db "gdi32", 0
### init ap0$ db ??000E+1, "GetStdHandle", 0
### init ap1$ db ??0022+1, "lstrlenA", 0
### init ap2$ db ??0036+1, "WriteFile", 0
### init ap3$ db ??0134+1, "sprintf", 0
### init ap4$ db ??019A+1, "Sleep", 0
### init ap5$ db ??036F+1, "GetModuleHandleA", 0
### init ap6$ db ??0383+1, "LoadIconA", 0
### init ap7$ db ??042C+1, "LoadCursorA", 0
### init ap8$ db ??0514+1, "SetLastError", 0
### init ap9$ db ??0528+1, "RegisterClassExA", 0
### init ap10$ db ??0593+1, "GetLastError", 0
### init ap11$ db ??05A7+1, "FormatMessageA", 0
### init ap12$ db ??0638+1, "LoadMenuA", 0
### init ap13$ db ??0734+1, "CreateWindowExA", 0
### init ap14$ db ??08D6+1, "GetMessageA", 0
### init ap15$ db ??08EA+1, "TranslateMessage", 0
### init ap16$ db ??08FE+1, "DispatchMessageA", 0
### init ap17$ db ??0912+1, "ExitProcess", 0
### init ap18$ db ??0DB7+1, "SendMessageA", 0
### init ap19$ db ??0DCB+1, "GetStockObject", 0
### init ap20$ db ??0DF3+1, "SetFocus", 0
### init ap21$ db ??0E46+1, "InvalidateRect", 0
### init ap22$ db ??0F82+1, "BeginPaint", 0
### init ap23$ db ??0FD5+1, "SetTextColor", 0
### init ap24$ db ??0FE9+1, "SetBkColor", 0
### init ap25$ db ??0FFE+1, "TextOutA", 0
### init ap26$ db ??103E+1, "EndPaint", 0
### init ap27$ db ??10A5+1, "MoveWindow", 0
### init ap28$ db ??1173+1, "PostQuitMessage", 0
### init ap29$ db ??11E4+1, "DefWindowProcA", 0
Microsoft (R) Macro Assembler (x64) Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

*** Link using polink with sub Console    /entry:start "Skel6432GUI_4Prologue.obj" rsrc.res /OUT:"Skel6432GUI_4Prologue64.exe" ***


***    build all took 395 ms    ***
« OK »

rrr314159

That's a good article. It's for VS users but his MACRO discussion is useful to others as well. He recommends the MASM Programmer's Guide "that was originated in 1992 by Microsoft but still so valuable in today's MASM learning" - MASM 6.1! MS programming tools have made no progress for 24 years. Notice that he uses Kip Irvine when teaching assembler; someday I should glance at that book.

From the article: "please refer to TIOBE Programming Community Index, the ranking of Assembly Language is on the rise recently, which means different types of assembly languages play an important role in new device development. Academically, Assembly Language Programming is considered as a demanding course in Computer Science."

Seems assembly is finally getting some respect at M$?
I am NaN ;)

Zen

LIAOMI,
Thanks for the link. I like the way the author works through all the code (and the debug output), as if we were all idiots. :bgrin: