rlset.asm
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:4k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. TITLE RLSET - RSET and LSET statements
  2. PAGE 56,132
  3. ;***
  4. ; RLSET - RSET and LSET statements
  5. ;
  6. ; Copyright <C> 1986, Microsoft Corporation
  7. ;
  8. ;Purpose:
  9. ;
  10. ; BASIC Syntax mapping to included runtime entry points:
  11. ;
  12. ; - LSET Statement:
  13. ;
  14. ;      LSET stringvar = x$
  15. ;  |
  16. ;      B$LSET
  17. ;
  18. ; - RSET Statement:
  19. ;
  20. ;      RSET stringvar = x$
  21. ;  |
  22. ;      B$RSET
  23. ;
  24. ;******************************************************************************
  25. INCLUDE switch.inc
  26. INCLUDE rmacros.inc ; Runtime Macro Defintions
  27. USESEG DK_TEXT 
  28. INCLUDE seg.inc 
  29. assumes CS,DK_TEXT
  30. sBegin DK_TEXT 
  31. externNP B$STDALCTMP
  32. SUBTTL B$RSET, B$LSET - RSET and LSET statements
  33. PAGE
  34. ;***
  35. ; B$RSET, B$LSET - RSET and LSET statements
  36. ;
  37. ;Function:
  38. ; Copy source to destination. If destination is larger than source,
  39. ; pad with blanks. RSET has leading blanks, LSET trailing blanks.
  40. ;
  41. ; NOTE: This routine can take a far pointer to a movable item in a heap. This
  42. ; routine cannot directly or indirectly cause heap movement.
  43. ;
  44. ;Inputs:
  45. ; psdSource = Address of source string descriptor
  46. ; pDest  = far address of destination
  47. ; cbDest = length of destination foixed length string, or 0 if sd
  48. ;
  49. ;Outputs:
  50. ; None.
  51. ;
  52. ;Registers:
  53. ; per convention
  54. ;
  55. ;******************************************************************************
  56. cProc B$RSET,<PUBLIC,FAR>,<ES,SI,DI> 
  57. parmW psdSource
  58. parmD psdDest 
  59. parmW cbDest ; length of destination string
  60. cBegin
  61. CALL PREP ;Set up registers (source in SI, dest in DI)
  62. PUSH AX ;Save count of characters to copy
  63. XCHG AX,DX ;put blanks in AX
  64. REP STOSW
  65. JNC SKPSTO ;See if we need an odd number
  66. STOSB ;Put in that last blank
  67. SKPSTO:
  68. POP CX ;Count of characters to copy
  69. REP MOVSB ;Must move bytes for case source=dest
  70. POPSET:
  71. CALL B$STDALCTMP ;Delete source if a temp
  72. cEnd
  73. cProc B$LSET,<PUBLIC,FAR>,<ES,SI,DI> 
  74. parmW psdSource
  75. parmD psdDest 
  76. parmW cbDest ; length of destination string
  77. cBegin
  78. CALL PREP
  79. XCHG AX,CX ;Get move count in CX - save fill in AX
  80. REP MOVSB ;Must use bytes for case source = dest
  81. XCHG CX,AX ;Get count of blanks to fill in CX
  82. XCHG AX,DX ;put blanks in AX
  83. REP STOSW
  84. JNC POPSET ;See if an odd count
  85. STOSB ;Do that last byte
  86. JMP SHORT POPSET
  87. cEnd <nogen>
  88. ;***
  89. ;PREP - sets up registers for RSET and LSET
  90. ;
  91. ;Purpose:
  92. ; This routine sets up the registers for LSET and RSET.
  93. ;
  94. ;Entry:
  95. ; psdSource = Source string descriptor
  96. ; pDest     = Destination
  97. ; cbDest    = length of destination (0 if sd)
  98. ;
  99. ;Exit:
  100. ; [AX]   = Number of byte to move from source to dest.
  101. ; [BX]   = offset of source string descriptor
  102. ; [CX]   = Number of blanks to pad (in words,zero if source size > dest size)
  103. ; [DX]   = "  " 2 spaces for blank filling
  104. ; [ES:DI] = Destination data address
  105. ; [SI]   = Source DS offset
  106. ;
  107. ;Uses:
  108. ; eveything it returns
  109. ;
  110. ;******************************************************************************
  111. cProc PREP,<NEAR>
  112. cBegin
  113. psdSource  equ word ptr [bp+12] 
  114. pDest    equ dword ptr [bp+8]  
  115. cbDest    equ word ptr [bp+6]
  116. MOV SI,psdSource ;get source sd
  117. PUSH SI ; save it for later
  118. LODSW ;Get size of source string
  119. MOV SI,[SI]  ;Get source data address (LODSW added 2 to SI)
  120. LES DI,pDest ; [ES:DI] = address of dest data or sd
  121. MOV CX,cbDest ; Get size of dest string
  122. OR CX,CX ; if non-zer, we have what we need
  123. JNZ PREP_5 ; jump if ready
  124. MOV CX,[DI]  ; else get size of variable length string
  125. MOV DI,[DI+2] ; and ds offset (es assummed == ds)
  126. PREP_5:
  127. SUB CX,AX ;Number of blanks to pad with (dest - source)
  128. JAE RETL ;If not negative, we're done
  129. ADD AX,CX ;Set move count to size of dest string
  130. XOR CX,CX ;Set blank fill to zero
  131. RETL:
  132. SHR CX,1 ;Make byte count a word count
  133. MOV DX,"  "  ;2 blanks at a time
  134. POP BX ; [BX] = source sd
  135. cEnd
  136. sEnd DK_TEXT 
  137. END