home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / SRMACROS.INC < prev    next >
Text File  |  1993-09-14  |  5KB  |  149 lines

  1.  
  2. ; Macros which may be required for proper re-assembly
  3.  
  4. IF (target EQ 'M4')
  5. ;-----------------------------------------------------------------------------
  6. ;  MASM 4.0 does not allow retf and retn, allowed by current assemblers.
  7. ;  These marcos, convert RETF and RETN into data bytes that are acceptable
  8. ;  to MASM 4.0.
  9.  
  10.  
  11. retf            macro   ret_count               ; Fixup for Assembler
  12.                 if      ret_count+0 GT 1
  13.                 db      0CAh
  14.                 dw      ret_count
  15.                 else
  16.                 db      0CBh
  17.                 endif
  18. endm
  19.  
  20. retn            macro  ret_count
  21.                 if     ret_count+0 GT 1
  22.                 db     0C2h
  23.                 dw     ret_count
  24.                 else
  25.                 db     0C3h
  26.                 endif
  27. endm
  28.  
  29. ENDIF
  30.  
  31.  
  32. IF (target EQ 'M4') OR (target EQ 'M5') 
  33. ;-----------------------------------------------------------------------------
  34. ; Due to a bug in earlier MASM assemblers, the valid instruction type 
  35. ; "mov segreg, reg"  cannot be used, if the register is not AX.  
  36. ; For example:  mov  es, bx
  37.  
  38. movseg          macro reg16, unused, Imm16      ; Fixup for Assembler
  39.                 ifidn  <reg16>, <bx>            
  40.                 db     0BBh                     
  41.                 endif                           
  42.                 ifidn  <reg16>, <cx>            
  43.                 db     0B9h                     
  44.                 endif
  45.                 ifidn  <reg16>, <dx>
  46.                 db     0BAh
  47.                 endif
  48.                 ifidn  <reg16>, <si>
  49.                 db     0BEh
  50.                 endif
  51.                 ifidn  <reg16>, <di>
  52.                 db     0BFh
  53.                 endif
  54.                 ifidn  <reg16>, <bp>
  55.                 db     0BDh
  56.                 endif
  57.                 ifidn  <reg16>, <sp>
  58.                 db     0BCh
  59.                 endif
  60.                 ifidn  <reg16>, <BX>
  61.                 db     0BBH
  62.                 endif
  63.                 ifidn  <reg16>, <CX>
  64.                 db     0B9H
  65.                 endif
  66.                 ifidn  <reg16>, <DX>
  67.                 db     0BAH
  68.                 endif
  69.                 ifidn  <reg16>, <SI>
  70.                 db     0BEH
  71.                 endif
  72.                 ifidn  <reg16>, <DI>
  73.                 db     0BFH
  74.                 endif
  75.                 ifidn  <reg16>, <BP>
  76.                 db     0BDH
  77.                 endif
  78.                 ifidn  <reg16>, <SP>
  79.                 db     0BCH
  80.                 endif
  81.                 dw     seg Imm16
  82. endm
  83.  
  84. ENDIF
  85.  
  86.  
  87. IF (target EQ 'T3') or (target EQ 'T2')
  88. ;-----------------------------------------------------------------------------
  89. ; Some assemblers, like TASM, check each far call and jump, to see if it is
  90. ; in the same segment.  If so, rather than produce the standard five byte far 
  91. ; instruction it uses a near jump or call.
  92.  
  93. calls           macro   dummy1, dummy2, slocation
  94.                 db      9Ah                     ; forced call far instruction
  95.                 dw      offset slocation, seg slocation
  96. endm
  97.  
  98. jmps            macro   dummy1, dummy2, jlocation
  99.                 db      0EAh                    ; forced jump far instruction
  100.                 dw      offset jlocation, seg jlocation
  101. endm
  102.  
  103. ENDIF
  104.  
  105.  
  106.  
  107. IFE (target EQ 'NO')
  108. ;-----------------------------------------------------------------------------
  109. ;  Some compilers and some assemblers will code a call that goes to a far
  110. ;  subroutine in the same segment as:
  111. ;
  112. ;               PUSH    CS
  113. ;               CALL    near
  114. ;
  115. ;  This saves one byte, and is slightly faster.  If the assembler you are
  116. ;  using (i.e. MASM, Optasm) does not do this automatically, the following
  117. ;  macros are used to code the same information.  In other words, the binary
  118. ;  file has "PUSH CS, CALL near", and Sourcer ensures the same instructions
  119. ;  are used!  (macro CALLF)
  120. ;
  121.  
  122. callf           macro   location
  123.                 push    cs
  124.                 call    near ptr location
  125. endm
  126.  
  127. ;  Some compilers generate an unnecessary DS override on the call instruction
  128. ;  when compacting the CALLF type function.  Macro CALLFX handles this case.
  129.  
  130. callfx          macro   location
  131.                 push    cs
  132.                 db      3Eh
  133.                 call    near ptr location
  134. endm
  135.  
  136.  
  137. ;-----------------------------------------------------------------------------
  138. ;  Some compilers and some assemblers will code a near call that is the
  139. ;  selected assembler will convert to a short jump to save a byte.  This
  140. ;  reconstructs a near jump for these cases.
  141.  
  142. jmpn            macro   location
  143.                 db      0E9h
  144.                 dw      offset location-$-2
  145. endm
  146.  
  147. ENDIF
  148.  
  149.