NO

Author Topic: SIZEOF and DUP  (Read 8518 times)

Greenhorn

  • Guest
SIZEOF and DUP
« on: June 10, 2012, 08:53:20 pm »
Hi,

if I declare an array with DUP and SIZEOF as the length-expression POASM throws an error:
error: Expected 'identifier'.

For example:
myArray  BYTE  SIZEOF(someStruct)  DUP(0)

It would be a nice feature if POASM supports this. MASM does.


Regards
Greenhorn

Offline Vortex

  • Member
  • *
  • Posts: 531
    • http://www.vortex.masmcode.com
Re: SIZEOF and DUP
« Reply #1 on: June 10, 2012, 10:17:30 pm »
Hi Greenhorn,

The code below works fine and eax returns 28h which is the correct result :

Code: [Select]
.386
.model flat,stdcall
option casemap:none

BITMAPINFOHEADER STRUCT
  biSize            DWORD      ?
  biWidth           DWORD      ?
  biHeight          DWORD      ?
  biPlanes          WORD       ?
  biBitCount        WORD       ?
  biCompression     DWORD      ?
  biSizeImage       DWORD      ?
  biXPelsPerMeter   DWORD      ?
  biYPelsPerMeter   DWORD      ?
  biClrUsed         DWORD      ?
  biClrImportant    DWORD      ?
BITMAPINFOHEADER ENDS

ExitProcess PROTO :DWORD

includelib  \PellesC\lib\Win\kernel32.lib

.data

myArray BYTE SIZEOF(BITMAPINFOHEADER) dup(0)
x1      dd 10

.code

start:

    mov     eax,OFFSET x1 - OFFSET myArray   
    invoke  ExitProcess,0

END start
Code it... That's all...

Greenhorn

  • Guest
Re: SIZEOF and DUP
« Reply #2 on: June 10, 2012, 10:51:34 pm »
Hi Vortex,

hm, that irritates me.

POASM complains about the Name_ member:

Code: [Select]
IMAGE_AUX_SYMBOL_EX union
struct Sym
WeakDefaultSymIndex DWORD ? ;// the weak extern default symbol index
WeakSearchType DWORD ?
rgbReserved BYTE 12 dup (?)
ends
struct File
Name_ BYTE sizeof(IMAGE_SYMBOL_EX) dup (?)
ends
struct Section_
Length_ DWORD ? ;// section length
NumberOfRelocations WORD ? ;// number of relocation entries
NumberOfLinenumbers WORD ? ;// number of line numbers
CheckSum DWORD ? ;// checksum for communal
Number SWORD ? ;// section number to associate with
Selection BYTE ? ;// communal selection type
bReserved BYTE ?
HighNumber SWORD ? ;// high bits of the section number
rgbReserved BYTE 2 dup (?)
ends
struct
TokenDef IMAGE_AUX_SYMBOL_TOKEN_DEF <>
rgbReserved BYTE 2 dup (?)
ends
struct CRC
crc DWORD ?
rgbReserved BYTE 16 dup (?)
ends
IMAGE_AUX_SYMBOL_EX ends
PIMAGE_AUX_SYMBOL_EX typedef ptr IMAGE_AUX_SYMBOL_EX

So what's wrong in this ?

EDIT:
And here is the IMAGE_SYMBOL_EX structure:

Code: [Select]
IMAGE_SYMBOL_EX struct
union N
ShortName BYTE 8 dup (?)
struct Name_
Short_ DWORD ? ;// if 0, use LongName
Long DWORD ? ;// offset into string table
ends
LongName DWORD 2 dup (?) ;// PBYTE  [2]
ends
Value DWORD ?
SectionNumber SDWORD ?
Type_ WORD ?
StorageClass BYTE ?
NumberOfAuxSymbols BYTE ?
IMAGE_SYMBOL_EX ends
PIMAGE_SYMBOL_EX typedef ptr IMAGE_SYMBOL_EX


Greenhorn
« Last Edit: June 11, 2012, 03:58:30 pm by Greenhorn »

Offline Vortex

  • Member
  • *
  • Posts: 531
    • http://www.vortex.masmcode.com
Re: SIZEOF and DUP
« Reply #3 on: June 11, 2012, 09:59:53 pm »
Hi Greenhorn,

If it's possible, could you post a code example simulating the issue?
Code it... That's all...

Greenhorn

  • Guest
Re: SIZEOF and DUP
« Reply #4 on: June 11, 2012, 11:24:52 pm »
Yes of course it is.  ;)

I've translated some header files of the Windows SDK 7.1 and these structures are defined in the winnt.inc.
So I think it makes only sense if you have all the files for a proper test.

With JWASM it seems they work fine, but now I want to make them compatible for POASM.

However, the compressed archive is a little bit too big to attach it to a post here.
I hope it is OK for you if I send you a link for download via PM ...
« Last Edit: June 11, 2012, 11:45:11 pm by Greenhorn »

Offline Vortex

  • Member
  • *
  • Posts: 531
    • http://www.vortex.masmcode.com
Re: SIZEOF and DUP
« Reply #5 on: June 12, 2012, 08:35:00 pm »
Hi Greenhorn,

Removing the brackets seems to solve the problem. Could you try the code portion below?

Code: [Select]
IMAGE_AUX_SYMBOL_EX union
.
.
.
struct File
Name_ BYTE sizeof IMAGE_SYMBOL_EX dup (?)
ends
.
.
.
IMAGE_AUX_SYMBOL_EX ends
Code it... That's all...

Greenhorn

  • Guest
Re: SIZEOF and DUP
« Reply #6 on: June 13, 2012, 04:57:32 pm »
Hi Vortex,

yes, that solves the problem although if I don't understand why.
If I look into the documentation the brackets have the highest priority and should just evaluate the expression in it.

It's not a big thing but it would be nice if poasm wouldn't throw an error on this. I often use brackets for better reading, even if it's not always nessecary.

Thank you very much for your help.

Regards
Greenhorn

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2084
    • http://www.smorgasbordet.com
Re: SIZEOF and DUP
« Reply #7 on: June 17, 2012, 01:13:52 pm »
There seem to be a rather big difference between the documented and the actually supported syntax in MASM.
I have used the documented syntax. I can't find any documentation of parenthesis in sizeof.
/Pelle

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 761
Re: SIZEOF and DUP
« Reply #8 on: June 17, 2012, 07:13:00 pm »
There seem to be a rather big difference between the documented and the actually supported syntax in MASM.
I have used the documented syntax. I can't find any documentation of parenthesis in sizeof.
I am using MASM since '82 (actually earlier on  Z80/8080) and I can't remember that this ever was a supported syntax, so I doubt that there is any documentation about using parenthesis...

Ralf

Greenhorn

  • Guest
Re: SIZEOF and DUP
« Reply #9 on: June 20, 2012, 07:24:54 pm »
I am using MASM since '82 (actually earlier on  Z80/8080) and I can't remember that this ever was a supported syntax, so I doubt that there is any documentation about using parenthesis...

I'm still a Greenhorn in coding, especially in assembler. But I just can say that MASM does accept parenthesis in most cases.

However, thanks for paying attention.


Greenhorn

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 567
    • Homepage
Re: SIZEOF and DUP
« Reply #10 on: June 20, 2012, 07:28:57 pm »
But I just can say that MASM does accept parenthesis in most cases.
If an application is accepting/ignoring something doesn't result in this being valid, you will always have to make sure that this complies to the standard.

Many compilers allow non-standard coding, which must be pointed out in the documentation.
---
Stefan

Proud member of the UltraDefrag Development Team

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2084
    • http://www.smorgasbordet.com
Re: SIZEOF and DUP
« Reply #11 on: July 08, 2012, 01:52:53 pm »
Well, I have put this on the "maybe" list for the future. Nothing will happen in version 7.00...
/Pelle