Developing Programs Equally Translatable in MASM and TASM

Now, consider the problem of writing programs equally translatable by both MASM and TASM. Conditional assembling is suited to this purpose. The most convenient approach is using the IFDEF directive and the ability of assemblers to specify symbolic constants. Both ML and TASM32 support the /D option, allowing you to specify such constants.

Listing 12.1 demonstrates a program that can be translated by both MASM and TASM. This program is easy. However, carefully studying this example will allow you to create more sophisticated compatible programs.

Listing 12.1: Using conventional assembling to develop a compatible program
image from book
 .586P ; Flat memory model .MODEL FLAT, STDCALL ; Check whether the MASM symbolic constant is defined IFDEF MASM ; Work with MASM EXTERN      ExitProcess@4:NEAR EXTERN      MessageBoxA@16:NEAR includelib c:\masm32\lib\kernel32.lib includelib c:\masm32\lib\user32.lib ELSE ; Work with TASM EXTERN      ExitProcess:NEAR EXTERN      MessageBoxA:NEAR includelib c:\tasm32\lib\import32.lib ExitProcess@4 = ExitProcess MessageBoxA@16 = MessageBoxA ENDIF ;------------------------------------------------ ; Data segment _DATA  SEGMENT MSG DB "An easy program",  0    TIT DB "Title", 0 _DATA  ENDS ; Code segment _TEXT  SEGMENT START:       PUSH  0       PUSH  OFFSET TIT       PUSH  OFFSET MSG       PUSH  0  ;  Screen descriptor       CALL  MessageBoxA@16 ;--------------------------------------       PUSH  0       CALL  ExitProcess@4 _TEXT ENDS END START 
image from book
 

To translate the program using MASM, use the following:

 ML  /c  /coff  /DMASM PROG.ASM     LINK /SUBSYSTEM:WINDOWS  PROG.OBJ 

To translate the same program using TASM, use the following:

 TASM32 /ml PROG.ASM     TLINK32 -aa  PROG.OBJ 

As you can see, everything is reduced to checking whether the MASM symbolic constant is defined (the /DMASM command-line option). Another problem is adding the @N suffix. You bypass this problem by using the = operator, with which the names are redefined.



The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net