August 01, 2005
By disassembling some test code, it's clear that inout parameters are just pointers that are implicitly dereferenced when needed.  And treating them as pointers using inline asm works just fine.  But the assembler seems to have problems referencing inout parameters < 32 bits in asm blocks.  Here's some sample code:

# version( test1 )
# {
#     byte fn( inout byte val )
#     {
#         asm
#         {
#             mov EAX, val;
#             mov AL, [EAX];
#         }
#     }
# }
#
# byte nonasm( inout byte val )
# {
#     return val;
# }
#
# void main()
# {
#     byte b;
#     nonasm( b );
# }

C:\code\d>dmd test -version=test1
test.d(7): bad type/size of operands 'mov'

If I compile without the version flag and inspect the code however, I see:

# _D5test16nonasmFKgZg    comdat
#         assume  CS:_D5test16nonasmFKgZg
#                 mov     AL,[EAX]
#                 ret

so I'm obviously doing the right thing.  I know I could get around this by making the block naked or by using pure asm to reference the variable, but this should not be necessary.


Sean