News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Masm bug? Workaround? WTF...

Started by japheth, October 21, 2012, 01:59:32 AM

Previous topic - Next topic

japheth

Masm v8 and above apparently have problems with code like this:


.386
.model flat, stdcall

.data

table label dword
dd 0
dd 1
dd 2
SIZE_TABLE equ ( $ - table ) / 4

foo proto :DWORD

.code
invoke foo, SIZE_TABLE   ;'invalid instruction operands' ????
end


It's no problem for Masm v6.1x. Anybody with a good proposal for a workaround?

qWord

this seems to work:
SIZE_TABLE TEXTEQU %( $ - table ) / 4
MREAL macros - when you need floating point arithmetic while assembling!

japheth


jj2007

Strangely enough, mov eax, SIZE_TABLE works fine.

This works with invoke, too:

table dd 0, 1, 2
SIZE_TABLE = lengthof table

... but I guess you have good reasons to choose a more exotic solution ;-)

japheth

Quote from: jj2007 on October 21, 2012, 04:36:27 AM
... but I guess you have good reasons to choose a more exotic solution ;-)

Yes - quite a few times there are entries enclosed in a if-endif block in the table.

Btw, the TEXTEQU workaround is not always compatible, because you can't make a text macro public. In such cases you need an additional helper equate.

jj2007

Here is one more option, it works with ml 6.15...10 and JWasm:

include \masm32\include\masm32rt.inc

.data

bigger=1   ; test if
dummct=0

dummy CATSTR <dumstr>, %dummct
dummct=dummct+1

table label dword
dummy STRUCT
   dd 0
   dd 1
   if bigger
      dd 2
   endif
   dd 2
dummy ENDS
SIZE_TABLE equ dummy   ;( $ - table ) / 4

dummy CATSTR <dumstr>, %dummct
dummct=dummct+1

table2 label dword
dummy STRUCT
   dd 0
   dd 1
   ife bigger
      dd 2
   endif
   dd 2
dummy ENDS
SIZE_TABLE2 equ dummy


foo proto :DWORD

.code
start:
   invoke foo, SIZE_TABLE   ;'invalid instruction operands' ????
   invoke foo, SIZE_TABLE2
   inkey " "

foo proc arg
   print str$(arg), 13, 10
   ret
foo endp
end start


TouEnMasm

Quote
table label dword
   dd 0
   dd 1
   dd 2
SIZE_TABLE dd $ - table
And you can do what you want of SIZE_TABLE
Fa is a musical note to play with CL

japheth

Quote from: ToutEnMasm on October 21, 2012, 07:03:08 PM
Quote
table label dword
   dd 0
   dd 1
   dd 2
SIZE_TABLE dd $ - table
And you can do what you want of SIZE_TABLE

Just Masm v8 has to be convinced yet:

table label dword
dd 0
dd 1
dd 2
;;SIZE_TABLE equ ( $ - table ) / 4
SIZE_TABLE dd $ - table

.code
push SIZE_TABLE*2   ;gives error 'constant expected'

:biggrin:

jj2007

Quote from: japheth on October 21, 2012, 07:30:17 PM
Just Masm v8 has to be convinced yet:

Yves' workaround works with my version of ML 8, but it inserts a dword into the .data section.

Correction for mine:
SIZE_TABLE equ dummy/4

TouEnMasm

If you made it an exercice of syntax,this one is perfect
Quote
table dd 0,
             1,
              2

and all work

Quote
   push sizeof table *2
   invoke foo,(sizeof table /4)
:biggrin:

Fa is a musical note to play with CL

japheth

Quote from: jj2007 on October 21, 2012, 08:04:24 PM
Yves' workaround works with my version of ML 8, but it inserts a dword into the .data section.

I was kidding, jj. Perhaps you're living in Italy for too long now and have lost the non-existing German sense of humor? ( hint: the previous remark is also not to be taken too seriously ).

I was trying to assemble a pretty huge Masm application (COMView) with Masm v8, and finally managed ( after modifying a few dozen locations to the "textequ" style ) to assemble it without errors.

This doesn't mean that I'm having a running application now. As it turned out, Masm v8 tends to make procedures public even if you have declared them private ( either by OPTION PROC:private or directly in the PROC directive ). So I've given up for now.

jj2007


japheth

Quote from: jj2007 on October 22, 2012, 02:26:52 AM
I can recommend JWasm ;-)

Thanks! However, I wanted to try Masm v8 because it does - or at least is supposed to do - something that jwasm cannot do yet: emit Codeview v8 symbolic debug info for a multi-module assembly application.

johnsa

My suggestion is to get the Codeview v8 into jwasm for 32 and 64bit :)
(Joking.. well not really). Jwasm is far superior, CV8 is the only thing missing for me to move all my work over to jwasm.

On a side note.. i have a strange issue with one particular project. It will assemble and link perfectly with MASM. It Assembles perfectly with JWASM too, but when I try to link I get:
error LNK2005: _$$$00020@0 already defined in spatialflow.obj

For the life of me I can't find any duplicate definitions and masm doesn't seem to have any issues.

TouEnMasm

Quote
For the life of me I can't find any duplicate definitions and masm doesn't seem to have any issues.
I know well this one.
Can be in an interface definition
interface STRUCT
         mafonction comethod2 ?
interface ENDS
mafonction proto
and masm disagree.





Fa is a musical note to play with CL