home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / section5 / cmacrosx.inc next >
Encoding:
Text File  |  1988-08-11  |  3.5 KB  |  95 lines

  1. ;       CMACROSX.INC
  2. ;
  3. ;       This file includes supplemental macros for two macros included
  4. ;       in CMACROS.INC: parmCP and parmDP. When these macros are used,
  5. ;       CMACROS.INC allocates either 1 or 2 words to the variables
  6. ;       associated with these macros, depending on the memory model in
  7. ;       use. However, parmCP and parmDP provide no support for automatically
  8. ;       adjusting for different memory models--additional program code
  9. ;       needs to be written to compensate for this. The loadCP and loadDP
  10. ;       macros included in this file can be used to provide additional
  11. ;       flexibility for overcoming this limit.
  12.  
  13. ;       For example, "parmDP pointer" will make space (1 word in small
  14. ;       and middle models and 2 words in compact, large, and huge models)
  15. ;       for the data pointer named "pointer". The statement
  16. ;       "loadDP ds,bx,pointer" can then be used to dynamically place the
  17. ;       value of "pointer" into DS:BX, depending on the memory model.
  18. ;       In small-model programs, this macro would generate the instruction
  19. ;       "mov dx,pointer" (it is assumed that DS already has the right
  20. ;       segment value); in large-model programs, this macro would generate
  21. ;       the statements "mov ds,SEG_pointer" and "mov dx,OFF_pointer".
  22.  
  23.  
  24. checkDS macro        segmt
  25.            diffcount = 0
  26.            irp d,<ds,DS,Ds,dS>                  ; Allow for all spellings
  27.               ifdif <segmt>,<d>                 ; of "ds".
  28.                  diffcount = diffcount+1
  29.               endif
  30.            endm
  31.            if diffcount EQ 4
  32.               it_is_DS = 0
  33.            else
  34.               it_is_DS = 1
  35.            endif
  36.         endm
  37.  
  38. checkES macro        segmt
  39.            diffcount = 0
  40.            irp d,<es,ES,Es,eS>                  ; Allow for all spellings
  41.               ifdif <segmt>,<d>                 ; of "es".
  42.                  diffcount = diffcount+1
  43.               endif
  44.            endm
  45.            if diffcount EQ 4
  46.               it_is_ES = 0
  47.            else
  48.               it_is_ES = 1
  49.            endif
  50.         endm
  51.  
  52. loadDP  macro        segmt,offst,dptr
  53.            checkDS segmt
  54.            if sizeD                             ; <-- Large data model
  55.               if it_is_DS
  56.                  lds  offst,dptr
  57.               else
  58.                  checkES segmt
  59.                  if it_is_ES
  60.                     les  offst,dptr
  61.                  else
  62.                     mov  offst,OFF_&dptr
  63.                     mov  segmt,SEG_&dptr
  64.                  endif
  65.               endif
  66.            else
  67.               mov  offst,dptr                   ; <-- Small data model
  68.               if it_is_DS EQ 0
  69.                  push ds                        ; If "segmt" is not DS,
  70.                  pop  segmt                     ; move ds to segmt.
  71.               endif
  72.            endif
  73.         endm
  74.  
  75. loadCP  macro        segmt,offst,cptr
  76.            if sizeC                             ; <-- Large code model
  77.               checkDS segmt
  78.               if it_is_DS
  79.                  lds offst,cptr
  80.               else
  81.                  checkES
  82.                  if it_is_ES
  83.                     les  offst,cptr
  84.                  else
  85.                     mov  segmt,SEG_&cptr
  86.                     mov  offst,OFF_&cptr
  87.                  endif
  88.               endif
  89.            else
  90.               push cs                           ; <-- Small code model
  91.               pop  segmt
  92.               mov  offst,cptr
  93.            endif
  94.         endm
  95.