Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - Porting a 16-bit DOS program to windows, and inline asm which uses
Quoting from http://www.digitalmars.com/ctg/ctgInlineAsm.html:Functions can change the values in the EAX, ECX, EDX, ESI, EDI >registers. Functions must preserve the values in the EBX, ESI, EDI, EBP, ESP, SS, CS, DS registers (plus ES and GS for the NT memory model). Feb 27 2005
My original report was for 8.41, but the problem also exists in the 8.42 beta (which I downloaded yesterday and tried today). Additionally, this might help track down the problem: Note: MAYBE_ESI is #define'd to esi in windows and si in DOS, and MAYBE_EDI to edi in windows, etc. Note #2: As I also stated in my previous post, trxf is a local variable defined as 'float trxf[4]'. These lines of asm code assemble as follows: Original asm code Assembles to ----------------- ------------ fsub dword ptr [trxf] d865bc fsub dword ptr [ebp-0x44] fsub dword ptr trxf[MAYBE_ESI] d866bc fsub dword ptr [esi-0x44] fsub dword ptr [trxf+MAYBE_ESI] d866bc fsub dword ptr [esi-0x44] fsub dword ptr trxf[MAYBE_EDI] d867bc fsub dword ptr [edi-0x44] fsub dword ptr [trxf+MAYBE_EDI] d867bc fsub dword ptr [edi-0x44] fsub dword ptr trxf[MAYBE_EAX] d860bc fsub dword ptr [eax-0x44] fsub dword ptr [trxf+MAYBE_EAX] d860bc fsub dword ptr [eax-0x44] fsub dword ptr trxf[MAYBE_EBX] d863bc fsub dword ptr [ebx-0x44] fsub dword ptr [trxf+MAYBE_EBX] d863bc fsub dword ptr [ebx-0x44] fsub dword ptr trxf[MAYBE_ECX] d861bc fsub dword ptr [ecx-0x44] fsub dword ptr [trxf+MAYBE_ECX] d861bc fsub dword ptr [ecx-0x44] fsub dword ptr trxf[MAYBE_EDX] d862bc fsub dword ptr [edx-0x44] fsub dword ptr [trxf+MAYBE_EDX] d862bc fsub dword ptr [edx-0x44] So [localVariable] is assembled correctly, but none of the others are. Omitting 'dword ptr' from the asm doesn't affect the assembled code (not that it should). I tried one last thing as a workaround: fsub dword ptr trxf[ebp+MAYBE_ESI] d86435bc fsub dword ptr [ebp+esi-0x44] fsub dword ptr [trxf+ebp+MAYBE_ESI] d86435bc fsub dword ptr [ebp+esi-0x44] So that compiled to what we were looking for originally, but amounted to artificially adding the missing ebp back, so when this bug gets fixed, I expect the workaround asm would probably either cause a compile-time error or turn into 'fsub dword ptr [ebp*2+esi-0x44]'. :P One more clarification: I have not compiled the program for DOS with DMC and checked to see if these compile right, and do not plan to at this time (It's a 16-bit program, and compiling it for DOS with BC 3.1 produces smaller EXEs and compiles properly, whereas DMC tends to push several of the code segments over the 64 KB limit, forcing functions to be moved around, with the end result being an EXE which was big enough that it didn't have enough RAM for its data-arrays). -SL Feb 28 2005
"SL" <shadowlord13 gmail.com> wrote in message news:d00b77$11uq$1 digitaldaemon.com...I tried one last thing as a workaround: fsub dword ptr trxf[ebp+MAYBE_ESI] d86435bc fsub dword ptr [ebp+esi-0x44] fsub dword ptr [trxf+ebp+MAYBE_ESI] d86435bc fsub dword ptr [ebp+esi-0x44] So that compiled to what we were looking for originally, but amounted to artificially adding the missing ebp back, so when this bug gets fixed, I expect the workaround asm would probably either cause a compile-time error or turn into 'fsub dword ptr [ebp*2+esi-0x44]'. :P Feb 28 2005
Ah. Well, thanks for your time. I'm happy as long as I can count on it to stay the same in future versions. Now I just need to find all the places where the asm code does that kind of thing... (Of course, an optional compiler flag to always include ebp could be useful to anyone porting things from BC, and wouldn't affect existing inline asm code - Though there are already a lot of compiler flags, and maybe that's too special-case to deserve one) -SL Mar 01 2005
|