News:

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

Main Menu

who knows that unusual MASM syntax...

Started by qWord, March 04, 2013, 02:18:05 AM

Previous topic - Next topic

qWord

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
MREAL macros - when you need floating point arithmetic while assembling!

dedndave


qWord

MREAL macros - when you need floating point arithmetic while assembling!

dedndave

oh - lol

well - i think there are easier ways to do both
you know the ways i am refering to

jj2007

MasmBasic's CreateInvoke/CreateInvokeC, ImportC and gsl macros use it.

qWord

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.
MREAL macros - when you need floating point arithmetic while assembling!

KeepingRealBusy

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.

Vortex

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

qWord

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.
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

#9
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?

qWord

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.
MREAL macros - when you need floating point arithmetic while assembling!