Roland <rv@ronetech.com> wrote in message news:3D50F00A.EBF0567@ronetech.com...
 

KarL a écrit :

Source:
.
.
somepublicfunction()
{
    __asm   mov dx, 0x300
    __asm   mov al, m_cC
    __asm   out dx,al
}


you are loading the offset of m_cC in al !
you have to do like this:

asm    mov  eax,this
asm    mov  al,[eax].m_cC

roland 

NO. It shouldn't even compile at all!
 
somepublicfunction() is a global function and is unable to even see m_cC!
 
Borland's compilers both returns the following messages:
C:\tmp\bugtest>bcc32 -S bug.cpp
Borland C++ 5.0 for Win32 Copyright (c) 1993, 1996 Borland International
bug.cpp:
Error bug.cpp 9: Type 'someobj' may not be defined here
Warning bug.cpp 13: Function should return a value in function somepublicfunction()
Error bug.cpp 18: Expression syntax in function someobj::somebuggyfunction()
*** 2 errors in Compile ***
C:\tmp\bugtest>bcc -S bug.cpp
Borland C++ 5.0 Copyright (c) 1987, 1996 Borland International
bug.cpp:
Error bug.cpp 9: Type 'someobj' may not be defined here
Warning bug.cpp 13: Function should return a value in function somepublicfunction()
Error bug.cpp 18: Expression syntax in function someobj::somebuggyfunction()
*** 2 errors in Compile ***
What was missed in the defination of the class someobj is at the end of the class
defination, there was NO ';' at the end of the '}' after the defination of someobj.
 
What I change it to this:
class someobj {
    unsigned char m_cC;    // This is private to someobj only
public:
    void somebuggyfunction();
    void somefunction();
}; // NOTICE THE ';' now...
somepublicfunction()    // This is a global function
{
    __asm   mov dx, 0x300
    __asm   mov al, m_cC    // trying to access non global variable
    __asm   out dx,al
}
void someobj::somebuggyfunction()
{
    __asm   mov dx, 0x300
    __asm   mov al, m_cC    // Question, 16-bit and 32-bit compatible???
    __asm   out dx,al
}
void someobj::somefunction()
{
    m_cC = 0x56;
}
Borland compilers now says:
C:\tmp\bugtest>bcc -S bug.cpp
Borland C++ 5.0 Copyright (c) 1987, 1996 Borland International
bug.cpp:
Warning bug.cpp 13: Function should return a value in function somepublicfunctio
n()
Error bug.cpp 18: Expression syntax in function someobj::somebuggyfunction()
*** 1 errors in Compile ***
C:\tmp\bugtest>bcc32 -S bug.cpp
Borland C++ 5.0 for Win32 Copyright (c) 1993, 1996 Borland International
bug.cpp:
Warning bug.cpp 13: Function should return a value in function somepublicfunctio
n()
Error bug.cpp 18: Expression syntax in function someobj::somebuggyfunction()
*** 1 errors in Compile ***
It now correctly informed me that I can't use that expression for accessing the class member m_cC but
also failed to tell me that someglobalfunction cannot see m_cC.
 
If I change the someglobalfunction()'s accessing of m_cC into something else, DM will tell me this:
C:\tmp\bugtest>sc -C bug.cpp
        __asm   mov     al, ThisIsABogusVariable
                                               ^
bug.cpp(11) : Warning 13: Illegal type/size of operands for the mov instruction
}
^
bug.cpp(13) : Error: undefined label 'ThisIsABogusVariable'
--- errorlevel 1
This is what should have been expected.
 
To make both DM and BC compilers happy, and also 16-bit and 32-bit source level compatible,
this is the fix:
void someobj::somebuggyfunction()
{
    unsigned char uc = m_cC;    // Use the stack to get member variable
    __asm   mov dx, 0x300
    __asm   mov al, uc          // Now both 16-bit and 32-bit is OK... (I think)
    __asm   out dx,al
}
 
 
Have a nice day Walter.  ;-)