The MASM Forum

General => The Campus => Topic started by: qWord on March 04, 2013, 02:18:05 AM

Title: who knows that unusual MASM syntax...
Post by: qWord on March 04, 2013, 02:18:05 AM
I'm curious who of you knows, or already has used the following (unusual) syntax:


; example 1
PtrWORD typedef ptr WORD
; access a WORD
mov [PtrWORD ptr eax],0

; example 2
foo struct
x DWORD ?
y DWORD ?
foo ends
Pfoo typedef ptr foo
mov [Pfoo ptr eax].y,0

The MASM's programmer's guide does not say anything about that possibility. IIRC I've read about that long ago in an post on win32asmcommunity.

regards, qWord

EDIT: +MASM
Title: Re: who knows that unusual syntax...
Post by: dedndave on March 04, 2013, 02:33:54 AM
GoAsm ?
Title: Re: who knows that unusual syntax...
Post by: qWord on March 04, 2013, 03:31:23 AM
Quote from: dedndave on March 04, 2013, 02:33:54 AM
GoAsm ?
no, I was referring to MASM.
Title: Re: who knows that unusual MASM syntax...
Post by: dedndave on March 04, 2013, 03:36:49 AM
oh - lol

well - i think there are easier ways to do both
you know the ways i am refering to
Title: Re: who knows that unusual MASM syntax...
Post by: jj2007 on March 04, 2013, 03:55:22 AM
MasmBasic's CreateInvoke/CreateInvokeC, ImportC and gsl macros use it.
Title: Re: who knows that unusual MASM syntax...
Post by: qWord on March 04, 2013, 04:03:02 AM
Quote from: jj2007 on March 04, 2013, 03:55:22 AM
MasmBasic's CreateInvoke/CreateInvokeC, ImportC and gsl macros use it.
are you sure - jWasm didn't support it until the release of today.
Title: Re: who knows that unusual MASM syntax...
Post by: KeepingRealBusy on March 04, 2013, 06:43:02 AM
Quote from: qWord on March 04, 2013, 02:18:05 AM
I'm curious who of you knows, or already has used the following (unusual) syntax:


; example 1
PtrWORD typedef ptr WORD
; access a WORD
mov [PtrWORD ptr eax],0

; example 2
foo struct
x DWORD ?
y DWORD ?
foo ends
Pfoo typedef ptr foo
mov [Pfoo ptr eax].y,0

The MASM's programmer's guide does not say anything about that possibility. IIRC I've read about that long ago in an post on win32asmcommunity.

regards, qWord

EDIT: +MASM

I usually use only the base, index, and offset inside the [] and qualify it outside

mov PtrWORD [eax+ebx*4+AnOffset],value


Dave.
Title: Re: who knows that unusual MASM syntax...
Post by: Vortex on March 04, 2013, 07:06:00 AM
Not exactly the same but the code below is assembled with Poasm V7.00.3 :


.386
.model flat,stdcall
option casemap:none

PtrWORD typedef ptr WORD

foo struct
x DWORD ?
y DWORD ?
foo ends

Pfoo typedef ptr foo

.data?

buffer  db 8 dup(?)

.code

start:

    mov     eax,OFFSET buffer
    mov     [PtrWORD ptr eax],0
    mov     [Pfoo ptr eax + foo.y],0
    ret

END start
Title: Re: who knows that unusual MASM syntax...
Post by: qWord on March 04, 2013, 08:53:25 AM
OK, I  see that actually nobody here sees why I call it "unusual": The examples make a typecast to a pointer type inside the square brackets. The clue is that the square brackets dereference the type thus in the first example < [PtrWORD ptr eax] > accesses a WORD and not a DWORD.
Title: Re: who knows that unusual MASM syntax...
Post by: jj2007 on March 04, 2013, 09:07:55 AM
Quote
Quote
        MasmBasic's CreateInvoke/CreateInvokeC, ImportC and gsl macros use it.
are you sure - jWasm didn't support it until the release of today.

I am sure that it never choked on the example 1 syntax. The gsl and CreateInvoke macros are about two years old.

Excerpt (line 8216 of MasmBasic.inc):
               tmptype typedef PROTO C :gslArgsLocal$   ; let invoke do the job
               gslType typedef PTR tmptype
               invoke gslType PTR ThisMac, args

where gslArgsLocal$ can be dword, real8 and other sizes.

Example 2 doesn't work - maybe because foo is a self-defined struct? Shouldn't make a difference, actually, because RECT works.

On further investigation, JWasm (from some days to some months old) accepts the syntax and assembles correctly if you feed correct input. If you feed incorrect input, e.g. ...
   PtrWORD typedef ptr RECT
   mov eax, [PtrWORD ptr esi]

... then JWasm assembles it and loads eax. Which it shouldn't do - ML complains indeed.

Complete example below.

include \masm32\include\masm32rt.inc
; example 1
PtrWORD typedef ptr WORD
; access a WORD
; mov [PtrWORD ptr eax],0

; example 2
foo struct
   x DWORD ?
   y DWORD ?
foo ends
Pfoo typedef ptr foo
.data
myX   dd 12345678
.code
start:
   mov esi, offset myX
   mov eax, [PtrWORD ptr esi]
   inkey str$(eax)
   exit
   ; mov [Pfoo ptr eax].y,0
   mov [PtrWORD ptr eax],0

end start

Quote from: qWord on March 04, 2013, 04:03:02 AMJWasm (..) accepts the syntax and assembles correctly if you feed correct input.

As written above, older JWasm versions also accepted incorrect input, which you rightly identified as a bug. Can you elaborate what you want to demonstrate with this thread?
Title: Re: who knows that unusual MASM syntax...
Post by: qWord on March 04, 2013, 09:26:44 AM
Quote from: jj2007 on March 04, 2013, 09:07:55 AMExcerpt (line 8216 of MasmBasic.inc):
               tmptype typedef PROTO C :gslArgsLocal$   ; let invoke do the job
               gslType typedef PTR tmptype
               invoke gslType PTR ThisMac, args
That method is common and well documented.
Quote from: jj2007 on March 04, 2013, 09:07:55 AM
Example 2 doesn't work - maybe because foo is a self-defined struct? Shouldn't make a difference, actually, because RECT works.
it does not work because previous version of jWasm does not do what MASM does: the pointer type is dereference, thus [Pfoo ptr eax] represents the structure value, which then can be used with the dot-operator to access structure fields.