Windows 16bit C Calling 32Bit ASM
Quote:
>> I am a C programmer but am very interested in assembly for speed and
>>the ability to use a flat memory model for holding images over 16MB and
>>without doing huge pointer math. From C using 16:16 Selector/Offset
>>scheme how do I call am assembly routine using 16:32 to modify my image.
>>Please help!!!!!!!
>As I understand, all you have to do is to allow 80386 instructions and use
>specification 'USE16' for the code segment in assembly. Otherwise the
>assembler tries to make it 32-bit and linker complains. After that use 32-bit
>offsets to your data in your assembly program.
>Hey All, correct me if I'm wrong.
That's correct. However, there is another way to do it: generate a 32 bit-assembly segment
with the USE32 directive. This segment must contain only 32 bit segments, you can't group it
with other segments. The 16bit linker will not complain, but the segments isn't loaded by Windows
as 32bit. So, at load time you must use DPMI-functions to adjust the segment-attributes to 32bit.
Now you can call the assembler function(s) from C, but you must be sure that the asm-function
does a 16bit return! Also special care must be taken if you use extended directives of TASM, such as
the C language support: it is not easy to let TASM generate correct code for 16bit-callers (but it is
possible. I used macros for ENTER/LEAVE, adjusting stack-ptrs).
Success
n u