News:

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

Main Menu

I must be doing something wrong...

Started by hyder, December 10, 2024, 06:33:20 AM

Previous topic - Next topic

hyder

I've been using a very old version of the MASM32 library for like, forever. Recently, my technical reviewer started complaining that the listings he's reviewing in "The Art of 64-bit Assembly, Vol 2" were getting all kinds of errors.

The problem, it seems, is that the MASM32 library changed quite a bit over the past several years since I first wrote Ao64Av2 (my include files are still present in an "include64" library, for example).

Okay, so I figure I'll download the latest version and see what's going on.
When I include the "Windows.inc" header files, I get assembly errors. Specifically,

DEBUGHOOKINFO STRUCT
  hModuleHook   DWORD      ?
  Reserved      DWORD      ?
  lParam        DWORD      ?
  wParam        DWORD      ?
  code          DWORD      ?
DEBUGHOOKINFO ENDS

it doesn't like the "code DWORD ?" line (isn't "code" a reserved word in MASM?)
Any ideas what is going on here?
Thanks,
Randy Hyde

zedd151

There have been errors reported with several include files, some for the masm32 SDK and many for the Masm64 SDK, which is missing a lot of include files as well.
My best advice is get a hold of the corresponding C header files for whichever API you are using, for either comparison (to the .inc file) for correctness, or to convert the C header file (.h) to a masm compatible ".inc" file.

I am not sure if "code" is reserved, but ".code" certainly is. Someone else may shed some light here. I am on my iPad so I can't easily check. I am not near a computer at the moment.

C3

Quote from: hyder on December 10, 2024, 06:33:20 AMI've been using a very old version of the MASM32 library for like, forever. Recently, my technical reviewer started complaining that the listings he's reviewing in "The Art of 64-bit Assembly, Vol 2" were getting all kinds of errors.

The problem, it seems, is that the MASM32 library changed quite a bit over the past several years since I first wrote Ao64Av2 (my include files are still present in an "include64" library, for example).

Okay, so I figure I'll download the latest version and see what's going on.
When I include the "Windows.inc" header files, I get assembly errors. Specifically,

DEBUGHOOKINFO STRUCT
  hModuleHook  DWORD      ?
  Reserved      DWORD      ?
  lParam        DWORD      ?
  wParam        DWORD      ?
  code          DWORD      ?
DEBUGHOOKINFO ENDS

it doesn't like the "code DWORD ?" line (isn't "code" a reserved word in MASM?)
Any ideas what is going on here?
Thanks,
Randy Hyde


1st. I like your books :)

2nd. You are doing MASM64, I assume from the context. Hutch's MASM64 SDK does'nt have DEBUGHOOKINFO STRUCT. Searching Windows SDK C++ headers is as follow:

/*
 * Structure used by WH_DEBUG
 */
typedef struct tagDEBUGHOOKINFO
{
    DWORD  idThread;
    DWORD  idThreadInstaller;
    LPARAM  lParam;
    WPARAM  wParam;
    int    code;
} DEBUGHOOKINFO, *PDEBUGHOOKINFO, NEAR *NPDEBUGHOOKINFO, FAR* LPDEBUGHOOKINFO;

And I assume that LPARAM and WPARAM in 64bit are QWORD's in Windows 64bit. Windows Docs say that code member is: The value to be passed to the hook in the nCode parameter of the DebugProc callback function.

Tried add the structure to some custom project, It doesnt assemble source with that structure what you did post. I did found that Hutch used as follows in another structure.

  NMHDR STRUCT
    hwndFrom    HWND ?
    idFrom      UINT_PTR ?
    _code       UINT ?
                UINT ?
  NMHDR ENDS

MASM32 SDK contains it MASM64 SDK doesnt, it's needed to be translated. That MASM64 for some reason doesnt accept it in source, It's not mentioned in Directives Reference also.

Cheers Petter


TimoVJL

DEBUGHOOKINFO    20 14h bytes
idThread        +0h 4h
idThreadInstaller +4h 4h
lParam          +8h 4h
wParam          +Ch 4h
code            +10h 4h

DEBUGHOOKINFO    32 20h bytes
idThread        +0h 4h
idThreadInstaller +4h 4h
lParam          +8h 8h
wParam          +10h 8h
code            +18h 4h
May the source be with you

daydreamer

Don't sure if 64 bit ml still has
Nokeyword, which let you remove keyword status, for example my very old SSE2 macros I used Nokeyword so I could define some macros
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

ttribelli

It's not that things are missing, it's that existing headers have errors during assembly.

c:\masm32\include\windows.inc(9750) : error A2008:syntax error : dword
c:\masm32\include\windows.inc(10183) : error A2008:syntax error : frame
c:\masm32\include\windows.inc(16333) : error A2008:syntax error : dword
c:\masm32\include\windows.inc(18862) : error A2008:syntax error : Frame
c:\masm32\include\windows.inc(24749) : error A2042:statement too complex
c:\masm32\include\winextra.inc(4647) : error A2008:syntax error : tab
c:\masm32\include\winextra.inc(11052) : error A2026:constant expected
c:\masm32\include\winextra.inc(11053) : error A2026:constant expected

Our current workaround, masm32.inc:

; masm32.inc

            if          0   ; 1 to use masm32, 0 for local definitions

            include     c:\masm32\include\windows.inc
            include     c:\masm32\include\kernel32.inc
            includelib  c:\masm32\lib\kernel32.lib

            else

STILL_ACTIVE        equ     000000103h
INFINITE            equ     0FFFFFFFFh
TLS_OUT_OF_INDEXES  equ     0FFFFFFFFh

handle              TYPEDEF qword
HANDLE              TYPEDEF handle

CRITICAL_SECTION    struc
DebugInfo           qword   ?
LockCount           dword   ?
RecursionCount      dword   ?
OwningThread        handle  ?
LockSemaphore       handle  ?
SpinCount           dword   ?
                    dword   ?
CRITICAL_SECTION    ends

STARTUPINFO         STRUCT
    cb              dword   ?
    lpReserved      qword   ?
    lpDesktop       qword   ?
    lpTitle         qword   ?
    dwX             dword   ?
    dwY             dword   ?
    dwXSize         dword   ?
    dwYSize         dword   ?
    dwXCountChars   dword   ?
    dwYCountChars   dword   ?
    dwFillAttribute dword   ?
    dwFlags         dword   ?
    wShowWindow     word    ?
    cbReserved2     word    ?
    lpReserved2     qword   ?
    hStdInput       handle  ?
    hStdOutput      handle  ?
    hStdError       handle  ?
STARTUPINFO         ENDS

PROCESS_INFORMATION STRUCT
    hProcess        HANDLE  ?
    hThread         HANDLE  ?
    dwProcessId     DWORD   ?
    dwThreadId      DWORD   ?
PROCESS_INFORMATION ENDS

            extrn   __imp_CreateThread:ptr proc
            extrn   __imp_Sleep:ptr proc
            extrn   __imp_InitializeCriticalSection:ptr proc
            extrn   __imp_DeleteCriticalSection:ptr proc
            extrn   __imp_EnterCriticalSection:ptr proc
            extrn   __imp_LeaveCriticalSection:ptr proc
            extrn   __imp_GetExitCodeThread:ptr proc
            extrn   __imp_CreateEventA:ptr proc
            extrn   __imp_SetEvent:ptr proc
            extrn   __imp_WaitForSingleObject:ptr proc
            extrn   __imp_WaitForMultipleObjects:ptr proc
            extrn   __imp_CloseHandle:ptr proc
            extrn   __imp_CreateWaitableTimerA:ptr proc
            extrn   __imp_SetWaitableTimer:ptr proc
            extrn   __imp_CancelWaitableTimer:ptr proc
            extrn   __imp_GetLastError:ptr proc
            extrn   __imp_TlsAlloc:ptr proc
            extrn   __imp_TlsGetValue:ptr proc
            extrn   __imp_TlsSetValue:ptr proc
            extrn   __imp_TlsFree:ptr proc
            extrn   __imp_CreateProcessA:ptr proc
            extrn   __imp_GetCurrentThread:ptr proc
            extrn   __imp_SetThreadAffinityMask:ptr proc
            extrn   __imp_GetCurrentProcess:ptr proc
            extrn   __imp_GetProcessAffinityMask:ptr proc

CreateThread                equ __imp_CreateThread
Sleep                       equ __imp_Sleep
InitializeCriticalSection   equ __imp_InitializeCriticalSection
DeleteCriticalSection       equ __imp_DeleteCriticalSection
EnterCriticalSection        equ __imp_EnterCriticalSection
LeaveCriticalSection        equ __imp_LeaveCriticalSection
GetExitCodeThread           equ __imp_GetExitCodeThread
CreateEvent                 equ __imp_CreateEventA
SetEvent                    equ __imp_SetEvent
WaitForSingleObject         equ __imp_WaitForSingleObject
WaitForMultipleObjects      equ __imp_WaitForMultipleObjects
CloseHandle                 equ __imp_CloseHandle
CreateWaitableTimer         equ __imp_CreateWaitableTimerA
SetWaitableTimer            equ __imp_SetWaitableTimer
CancelWaitableTimer         equ __imp_CancelWaitableTimer
GetLastError                equ __imp_GetLastError
TlsAlloc                    equ __imp_TlsAlloc
TlsGetValue                 equ __imp_TlsGetValue
TlsSetValue                 equ __imp_TlsSetValue
TlsFree                     equ __imp_TlsFree
CreateProcess               equ __imp_CreateProcessA
GetCurrentThread            equ __imp_GetCurrentThread     
SetThreadAffinityMask       equ __imp_SetThreadAffinityMask
GetCurrentProcess           equ __imp_GetCurrentProcess     
GetProcessAffinityMask      equ __imp_GetProcessAffinityMask

            endif

jj2007

Quote from: ttribelli on December 11, 2024, 05:22:15 AMc:\masm32\include\windows.inc

If one day your employer declares C: taboo and forces you to install Masm32 on D:, you will have lots of surprises :cool:

hyder

Quote from: C3 on December 10, 2024, 07:32:54 AM
Quote from: hyder on December 10, 2024, 06:33:20 AMDEBUGHOOKINFO STRUCT
  hModuleHook  DWORD      ?
  Reserved      DWORD      ?
  lParam        DWORD      ?
  wParam        DWORD      ?
  code          DWORD      ?
DEBUGHOOKINFO ENDS




2nd. You are doing MASM64, I assume from the context. Hutch's MASM64 SDK does'nt have DEBUGHOOKINFO STRUCT. Searching Windows SDK C++ headers is as follow:


Cheers Petter



FWIW, I don't know if "code" is actually reserved. It is used as a class designation in the SEGMENT directive. AFAIKT, I'm not defining "code" anywhere in my header files (that could lead to an error).

Yes, Hutch's old code doesn't have this structure, it's present in the latest downloads.
I wanted to use the latest and greatest include files for "The Art of 64-bit Assembly, Volume 2" (which is currently in the technical review phase), but if the use of said files breaks all my code, then I suppose I'm going to have to package up the definitions I need and stick with that. Of course, this invites all kinds of ugliness as it creates a fork that isn't maintained by the MASM32 site. As such, something I really want to avoid.
Cheers,
Randy Hyde


NoCforMe

Regarding the reserved-word-ness of code, I just did a li'l test:
T STRUC
  code DD ?
T ENDS

.data
t T<>

code DD ?

It assembled, linked and ran fine. So apparently it's fine to use code as a variable or structure element name. Which I found surprising.
Assembly language programming should be fun. That's why I do it.

_japheth

Quote from: hyder on December 12, 2024, 11:16:22 AMFWIW, I don't know if "code" is actually reserved.

Reserved words are case-insensitive. So changing "code" to "CODE" and if the error persists, then it's indeed a reserved word.

With "OPTION NOKEYWORD:<code>" it's possible to remove the keyword and the code should assemble without errors.

With a few experiments one can see that CODE is indeed a directive now: it defines a code section and expects a name as argument:

        code abc
        mov al,0

Feeding the resulting .OBJ to "DUMPBIN /symbols", one can see that a section named "abc" has been defined, size 2. However, it seems pretty likely that this new CODE directive is due to a misunderstanding at MS - the directive should probably have been .CODE, and that indeed does still work ( and, IIRC, also works with ML.EXE ):

        .code abc
        mov al,0

 
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

NoCforMe

Quote from: _japheth on December 14, 2024, 05:13:49 PMReserved words are case-insensitive. So changing "code" to "CODE" and if the error persists, then it's indeed a reserved word.

That doesn't make sense; if, as you say, reserved words are case-insensitive (they are), then it should make no difference whether you write code or CODE or CoDe, right?
Assembly language programming should be fun. That's why I do it.

_japheth

Quote from: NoCforMe on December 14, 2024, 05:22:34 PMThat doesn't make sense; if, as you say, reserved words are case-insensitive (they are), then it should make no difference whether you write code or CODE or CoDe, right?

I guess I expressed myself in bad English. The sentence should be read as:

So if your change "code" to "CODE" and the error still persists, then it's indeed a reserved word.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

tenkey

A different test. Using the 64-bit assembler for 64-bit code.
Syntax error rather than undefined symbol.
"code" can replace ".code". I guess someone disliked leading dots.

Microsoft (R) Macro Assembler (x64) Version 14.41.34120.0  12/13/24 14:47:21
test1.asm                            Page 1 - 1


 00000000            .code
                    add    eax,code
test1.asm(2) : error A2008:syntax error : code
 00000000            .data
                ;code dword ?
                end
Microsoft (R) Macro Assembler (x64) Version 14.41.34120.0  12/13/24 15:58:37
test1.asm                            Page 1 - 1


 00000000            code
 00000000  03 05 00000000 R        add    eax,bcode
 00000000            .data
                ;code dword ?
 00000000 00000000        bcode dword ?
                end

tenkey

The code/.code equivalence of ml64 does not extend to the other simplified segment directives.

00000000 code abc
 00000000  03 05 00000006 R add eax,bcode
xyz
test1.asm(3) : error A2008:syntax error : xyz
data ;DATA2
test1.asm(4) : error A2008:syntax error : data
 00000006 00000032 bcode dword 50
data? ;BSS2
test1.asm(6) : error A2008:syntax error : data?
 0000000A 00000000 bdata dword ?
const ;RDATA2
test1.asm(8) : error A2008:syntax error : const
 0000000E 61 62 63 00 bconst db "abc",0
end