Author Topic: Passing a structure  (Read 3368 times)

nidud

  • Member
  • *****
  • Posts: 1827
    • https://github.com/nidud/asmc
Re: Passing a structure
« Reply #15 on: March 28, 2019, 08:33:32 AM »
I have checked MASM and MSVC for the 32-bit case and 3 byte strutures.
There is indeed a bug in MASM when using invoke with the 3 byte structure.

That seems to be the case, tested up to version 14.

Quote
On the other hand MSVC handles well the situation, it does not makes 2 pushes totaling 8 bytes, it reserves 4 bytes in the stack through "sub esp" and puts the structure there by moving 1 byte more 1 word.

Well, it pushes 4 byte to allocate the structure and 4 byte for the argument which tally up to 8 bytes. Given the structure is not initialized the optimized version may look like this:

    push ecx
    call _foo
    pop  ecx    ; C return
    ret

or this:

    sub  esp,4
    call _foo
    add  esp,4
    ret

Quote
The receiving end knows how to pick it correctly.

That will also work in MASM thought.

foo proc ms:MS3
    mov al,ms._1
    ret
foo endp

*   push    ebp
*   mov     ebp, esp
*   mov     al, byte ptr [ebp+9H]
*   leave
*   ret


LiaoMi

  • Member
  • ****
  • Posts: 628
Re: Passing a structure
« Reply #16 on: March 28, 2019, 08:40:55 AM »
I have checked MASM and MSVC for the 32-bit case and 3 byte strutures.
There is indeed a bug in MASM when using invoke with the 3 byte structure.
On the other hand MSVC handles well the situation, it does not makes 2 pushes totaling 8 bytes, it reserves 4 bytes in the stack through "sub esp" and puts the structure there by moving 1 byte more 1 word. The receiving end knows how to pick it correctly.

Not a bug but a feature :biggrin: we can create a good support request  :eusa_boohoo:

AW

  • Member
  • *****
  • Posts: 2529
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #17 on: March 28, 2019, 04:33:16 PM »
I made a report to Microsoft and am ready to wait 5 years for the fix.  ::)

https://developercommunity.visualstudio.com/content/problem/508122/masm-invoke-with-a-3-byte-struct.html

jj2007

  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Re: Passing a structure
« Reply #18 on: March 28, 2019, 05:58:25 PM »
Personally, I would never use a 3-byte structure; add one padding byte, and everything works fine. Anyway, here's a testbed for 32-bit Masm:
Code: [Select]
include \masm32\include\masm32rt.inc

S3 STRUCT
x0 db ?
x1 db ?
x2 db ?
; x3 db ?    ; uncomment, and it will work just fine
S3 ENDS

.data
s3b S3 <1, 2, 3>

.code
s3Test proc s3passed:S3
  lea edx, s3passed
  print hex$(edx), " is the address", 13, 10
  movzx eax, s3passed.x0
  print str$(eax), " = x0", 13, 10
  movzx eax, s3passed.x1
  print str$(eax), " = x1", 13, 10
  movzx eax, s3passed.x2
  print str$(eax), " = x2", 13, 10
  ret
s3Test endp

start:
;   int 3
  invoke s3Test, s3b ; UAsm: Error A2049: Invalid instruction operands
  inkey "buggy indeed"
  exit

end start

OPT_Assembler mlv14 ; no complaints but there is a FAT BUG

0040102B      ³.  A0 02204000       mov al, [402002] ; the S3 starts at 402000
00401030      ³.  66:50             push ax
00401032      ³.  66:FF35 02204000  push word ptr [402002]
00401039      ³.  E8 C2FFFFFF       call 00401000

AW

  • Member
  • *****
  • Posts: 2529
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #19 on: March 29, 2019, 06:04:26 PM »
I got a reply from an MSFT (Microsoft Fuzzy Technician):
"Need More Info" and added a comment.Thank you for your feedback! For us to investigate this further, could you please provide more details like reproducing steps about this issue and example issue code.we don't know how to reproduce this issue on my side as current description. We look forward to hearing from you!

They never understand on a first approach, we need to be patient.  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Re: Passing a structure
« Reply #20 on: March 29, 2019, 07:18:00 PM »
Give him my testbed, it shows the issue crystal clear. Of course, Fuzzy himself has never touched Masm, but there must be somebody at M$ who has coded some lines in assembly. I hope so, at least. There are rumours that compiler developers use assemblers.

Biterider

  • Member
  • ***
  • Posts: 437
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: Passing a structure
« Reply #21 on: March 29, 2019, 09:20:15 PM »
Hi
Point them to this topic. At least our forum can gain some attention on Redmond.
Biterider

AW

  • Member
  • *****
  • Posts: 2529
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #22 on: March 29, 2019, 09:59:53 PM »
Give him my testbed, it shows the issue crystal clear.
You can post your testbed but you will need to explain to them what the macros do with examples and documentation.

Point them to this topic.
:badgrin:

LiaoMi

  • Member
  • ****
  • Posts: 628
Re: Passing a structure
« Reply #23 on: March 30, 2019, 01:14:44 AM »
I got a reply from an MSFT (Microsoft Fuzzy Technician):
"Need More Info" and added a comment.Thank you for your feedback! For us to investigate this further, could you please provide more details like reproducing steps about this issue and example issue code.we don't know how to reproduce this issue on my side as current description. We look forward to hearing from you!

They never understand on a first approach, we need to be patient.  :biggrin:

They want a ready-made binary file to keep their heads off, so that in their free time they can play Sony PlayStation, in previous topics it was all the same  :eusa_clap:

AW

  • Member
  • *****
  • Posts: 2529
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #24 on: March 30, 2019, 05:06:26 AM »
They want a ready-made binary file to keep their heads off, so that in their free time they can play Sony PlayStation, in previous topics it was all the same  :eusa_clap:
Everything works like in a big hospital.
They have a Triage at the entrance that establish priorities and forward the complaints to Areas.
Each Area has a receptionist, like the Fuzzy guy that replied to me. He knows nothing about the problem or how o solve it, but must write a summary of the symptoms  and address the file to the specialist doctor.
 

TimoVJL

  • Member
  • ***
  • Posts: 488
Re: Passing a structure
« Reply #25 on: March 30, 2019, 05:22:40 AM »
Person or PC, at least makes same mistakes ;)
compare to this

So next reply is
Quote
Thank you for your feedback! Unfortunately, right now we don't have enough information to investigate this issue and find a solution. If this is still an issue for you, please update to our latest version. If you are still able to repro it, please provide us with more info!

BTW:
Code: [Select]
Lin Gao [MSFT]
Reputation 27
Posts 142
Following 0
Followers 0
Joined 11/18
May the source be with you

AW

  • Member
  • *****
  • Posts: 2529
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #26 on: April 01, 2019, 11:16:33 PM »
Let's see what come next,  8):
Thanks for taking the time to report this issue to us. We’ve filed a bug for this issue on the C++ team here. The status on this Developer Community item will be updated as that bug is looked at. Thanks again for reporting this to us.

LiaoMi

  • Member
  • ****
  • Posts: 628
Re: Passing a structure
« Reply #27 on: April 02, 2019, 06:58:10 AM »
Let's see what come next,  8):
Thanks for taking the time to report this issue to us. We’ve filed a bug for this issue on the C++ team here. The status on this Developer Community item will be updated as that bug is looked at. Thanks again for reporting this to us.

Great news! Thank you AW! Artificial intelligence could talk to us, suddenly asked where to get this little-known msvcrt.lib library :biggrin:.

AW

  • Member
  • *****
  • Posts: 2529
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #28 on: April 02, 2019, 04:28:25 PM »
Great news! Thank you AW! Artificial intelligence could talk to us, suddenly asked where to get this little-known msvcrt.lib library :biggrin:.

Hi LiaoMi,
msvcrt.lib is a problem these days. "Weird, my msvcrt.lib doesn't export printf… "
But I could not tell the MickeySoft representative to download the MASM32 SDK and have a msvcrt.lib with printf, they wouldn't use 3rd party generated libraries.
So, I built a VS 2017 project and put there as input the 3 libs required nowadays (since VS 2015) to produce a printf. Apparently it worked.  :biggrin:

TimoVJL

  • Member
  • ***
  • Posts: 488
Re: Passing a structure
« Reply #29 on: April 02, 2019, 06:16:45 PM »
But they can create one:
Code: [Select]
; lib.exe -DEF:msvcrt-os.def -OUT:msvcrt-os.lib
; link.exe -lib -DEF:msvcrt-os.def -OUT:msvcrt-os.lib
LIBRARY msvcrt.dll
EXPORTS
printf
May the source be with you