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

操作系统开发

开发平台:

Visual C++

  1. TITLE STRNUM - String to number and number to string conversions
  2. ;***
  3. ; STRNUM - String to number and number to string conversions
  4. ;
  5. ; Copyright <C> 1986, Microsoft Corporation
  6. ;
  7. ;Purpose:
  8. ;
  9. ; BASIC Syntax mapping to included runtime entry points:
  10. ;
  11. ;
  12. ; CVI Function:  CVL Function:
  13. ;
  14. ;   v = CVI(2-byte string)   v = CVL(4-byte string)
  15. ;     |   |
  16. ;  B$FCVI        B$FCVL
  17. ;
  18. ;
  19. ; CVS Function:  CVD Function:
  20. ;
  21. ;   v = CVS(4-byte string)   v = CVD(8-byte string)
  22. ;     |   |
  23. ;  B$FCVS        B$FCVD
  24. ;
  25. ;
  26. ; CVSMBF Function: CVDMBF Function:
  27. ;
  28. ;   v = CVSMBF(4-byte string)   v = CVDMBF(8-byte string)
  29. ;     |   |
  30. ;  B$FCSF        B$FCDF
  31. ;
  32. ;
  33. ; MKI$ Function: MKL$ Function:
  34. ;
  35. ;   v$ = MKI$(integer exp)   v$ = MKL$(long integer exp)
  36. ;      |    |
  37. ;  B$FMKI        B$FMKL
  38. ;
  39. ;
  40. ; MKS$ Function: MKD$ Function:
  41. ;
  42. ;   v$ = MKS$(s.p. exp)    v$ = MKD$(d.p. exp)
  43. ;      |    |
  44. ;  B$FMKS        B$FMKD
  45. ;
  46. ;
  47. ; MKSMBF$ Function: MKDMBF$ Function:
  48. ;
  49. ;   v$ = MKSMBF$(s.p. exp)   v$ = MKDMBF$(d.p. exp)
  50. ;      |    |
  51. ;   B$FMSF B$FMDF
  52. ;
  53. ;******************************************************************************
  54. INCLUDE switch.inc
  55. INCLUDE rmacros.inc ; Runtime Macro Defintions
  56. useSeg ST_TEXT
  57. useSeg _TEXT
  58. useSeg _DATA
  59. useSeg _BSS
  60. INCLUDE seg.inc
  61. INCLUDE baslibma.inc
  62. INCLUDE string.inc
  63. sBegin _DATA
  64. externW B$AC
  65. externW B$DAC
  66. sEnd _DATA
  67. sBegin _BSS
  68. externB b$Buf3 ; temporary space
  69. sEnd _BSS
  70. externFP B$ERR_OV ; FAR because it's JMP'ed to from _TEXT
  71. sBegin _TEXT
  72. externNP $i4_m4
  73. externNP $i8_m8
  74. externNP $m4_i4
  75. externNP $m8_i8
  76. sEnd _TEXT
  77. sBegin ST_TEXT
  78. externNP B$STDALCTMP
  79. externNP B$STALCTMPCPY
  80. externNP B$STALCTMP
  81. externNP B$ERR_FC
  82. ASSUMES CS,ST_TEXT
  83. SUBTTL
  84. PAGE
  85. ;***
  86. ;STRCPY - copy CX bytes from string to given location & free string if temp.
  87. ;
  88. ;Purpose:
  89. ; This routine is shared code for the CVS/CVD/... routines. Must be far, since
  90. ; it is called from another segment in some routines defined below.
  91. ;
  92. ;Entry:
  93. ; [BX] = pointer to a string descriptor.
  94. ; [CX] = count of bytes to copy from the string
  95. ; [DI] = target address for the copy.
  96. ;
  97. ;Exit:
  98. ; The copy is made, and the string is deallocated it temp.
  99. ; [AX] = pointer to the start of the target address (input DI)
  100. ;
  101. ;Modifies:
  102. ; Per Convention
  103. ;
  104. ;******************************************************************************
  105. cProc STRCPY,FAR,<DI,SI,ES>  ; added this routine to save code
  106. cBegin
  107. CMP BYTE PTR[BX],CL ;See if string is long enough
  108. JB ARGERR
  109. PUSH DS
  110. POP ES ;[ES] = [DS]
  111. MOV SI,[BX+2] ;Get address of data area
  112. PUSH DI ;save for retval
  113. REP MOVSB ;copy the string data
  114. CALL B$STDALCTMP ;Delete string if temp
  115. POP AX ;pointer to target address
  116. cEnd
  117. ARGERR: JMP B$ERR_FC ;Illegal function call
  118. ;***
  119. ; B$FCVI - Convert string to integer
  120. ;
  121. ;Function:
  122. ; Make sure string is at least 2 bytes long, then return the first 2 bytes
  123. ; as an integer.
  124. ;
  125. ;Inputs:
  126. ; sdNum = string descriptor
  127. ;
  128. ;Outputs:
  129. ; [AX] = number
  130. ;
  131. ;Registers:
  132. ; Per convention
  133. ;
  134. ;******************************************************************************
  135. cProc B$FCVI,<FAR,PUBLIC>
  136. cBegin <nogen>
  137. MOV CL,2 ;[CL] = length to do
  138. SKIP 2 ; fall through - share code
  139. cEnd nogen
  140. ;***
  141. ; B$FCVL - Convert string to long integer
  142. ;
  143. ;Function:
  144. ; Make sure string is at least 4 bytes long, then return the first 4 bytes
  145. ; as a long integer.
  146. ;
  147. ;Inputs:
  148. ; sdNum = string descriptor
  149. ;
  150. ;Outputs:
  151. ; [DX:AX]  = number
  152. ;
  153. ;Registers:
  154. ; Per convention
  155. ;
  156. ;******************************************************************************
  157. cProc B$FCVL,<FAR,PUBLIC>
  158. cBegin <nogen>
  159. MOV CL,4 ;[CL] = length to be copied
  160. XOR CH,CH
  161. cEnd <nogen> ; fall through to common code
  162. cProc BFCV_Int,<FAR>,DI
  163. parmSD sdNum
  164. cBegin
  165. GetpSD BX,sdNum ; [BX] = psdNum
  166. MOV DI,OFFSET DGROUP:B$AC ;[DI] = pointer to dummy place to copy
  167. CALL STRCPY
  168. XCHG AX,BX ;[BX] = pointer to number
  169. MOV AX,[BX]  ;[AX] = low word of number (both CVL and CVS)
  170. MOV DX,[BX+2] ;[DX] = high word (CVL only, else garbage)
  171. cEnd
  172. ;***
  173. ; B$FCVS, B$FCVD - Convert string to single or double precision number
  174. ;
  175. ;Function:
  176. ; Convert the string to single or double precision number. Make sure it's long
  177. ; enough first.
  178. ;
  179. ;Inputs:
  180. ; sdNum = string descriptor
  181. ;
  182. ;Outputs:
  183. ; [AX] = pointer to resulting number in FAC/DAC
  184. ;
  185. ;Registers:
  186. ; per convention
  187. ;******************************************************************************
  188. cProc B$FCVS,<FAR,PUBLIC>
  189. cBegin <nogen>
  190. MOV CL,4
  191. SKIP 2
  192. cEnd <nogen> ; fall through to share code
  193. cProc B$FCVD,<FAR,PUBLIC>
  194. cBegin <nogen>
  195. MOV CL,8
  196. XOR CH,CH
  197. cEnd <nogen>
  198. cProc BFCV_Real,<FAR>,DI
  199. parmSD sdNum
  200. cBegin
  201. MOV DI,OFFSET DGROUP:B$DAC
  202. GetpSD BX,sdNum ; [BX] = psdNum
  203. CALL STRCPY
  204. cEnd
  205. ;***
  206. ; B$FMKI, B$FMKL, B$FMKS, B$FMKD - Convert number to string
  207. ;
  208. ;Function:
  209. ; Create a 2-, 4-, or 8-byte temp string and put the number in it.
  210. ;
  211. ;Inputs:
  212. ; ivar = Integer to be converted (MKI)
  213. ; lvar = Long integer to be converted (MKL)
  214. ; R4var = real (s.p.) number to be converted (MKS)
  215. ; R8var = real (d.p.) number to be converted (MKD)
  216. ;
  217. ;Outputs:
  218. ; [AX] = Address of string descriptor
  219. ;
  220. ;Registers:
  221. ; Per convention
  222. ;
  223. ;******************************************************************************
  224. cProc B$FMKI,<FAR,PUBLIC>
  225. parmW ivar
  226. cBegin
  227. MOV BX,2 ;Create a string of length 2
  228. LEA DX,ivar ; [DX] = pointer to input parm
  229. CALL B$STALCTMPCPY ; Allocate string and copy data in
  230. XCHG AX,BX ; [AX] = pointer to descriptor
  231. cEnd
  232. cProc B$FMKL,<FAR,PUBLIC>
  233. cBegin <nogen>
  234. cEnd <nogen> ; share code with B$FMKS
  235. cProc B$FMKS,<FAR,PUBLIC>
  236. parmD R4num
  237. cBegin
  238. MK_4:
  239. MOV BX,4 ;Create a string of length 4
  240. LEA DX,R4num ; [DX] = pointer to input parm
  241. CALL B$STALCTMPCPY ; Allocate string and copy data in
  242. XCHG AX,BX ; [AX] = pointer to descriptor
  243. cEnd
  244. cProc B$FMKD,<FAR,PUBLIC>
  245. parmQ R8num
  246. cBegin
  247. MOV BX,8 ;4 Bytes in single precision number
  248. LEA DX,R8num  ;[DX] = pointer to data
  249. CALL B$STALCTMPCPY ;Allocate string and copy data in
  250. XCHG AX,BX ;[AX] = pointer to descriptor
  251. cEnd
  252. sEnd ST_TEXT
  253. sBegin _TEXT
  254. assumes CS,_TEXT
  255. ;***
  256. ;Ix_Mx
  257. ;
  258. ;Purpose:
  259. ; Since the low-level conversion functions (MBF to/from IEEE) are near routines
  260. ; in _TEXT, B$MCVS & B$MCVD call this routine to do the actual conversion
  261. ; (so they can be in ST_TEXT).
  262. ;
  263. ;Entry:
  264. ; AX is 4 if $i4_m4 is to called, 8 if $i8_m8 is to be called.
  265. ;
  266. ;******************************************************************************
  267. ;***
  268. ;Mx_Ix
  269. ;
  270. ;Purpose:
  271. ; Since the low-level conversion functions (MBF to/from IEEE) are near routines
  272. ; in _TEXT, B$FMSF & B$FMDF call this routine to do the actual conversion
  273. ; (so they can be in ST_TEXT).
  274. ;
  275. ;Entry:
  276. ; CX is 4 if $m4_i4 is to called, 8 if $m8_i8 is to be called.
  277. ;
  278. ;******************************************************************************
  279. IX_MX_DISP:
  280. DW _TEXTOFFSET $i4_m4 
  281. DW _TEXTOFFSET $i8_m8 
  282. MX_IX_DISP:
  283. DW _TEXTOFFSET $m4_i4 
  284. DW _TEXTOFFSET $m8_i8 
  285. cProc Ix_Mx,<FAR>
  286. cBegin <nogen>
  287. MOV BX,_TEXTOFFSET IX_MX_DISP 
  288. JMP SHORT Convert_Common 
  289. cEnd <nogen>
  290. cProc Mx_Ix,<FAR>
  291. cBegin <nogen>
  292. XCHG AX,CX ; put input into AX for common code, below
  293. MOV BX,_TEXTOFFSET MX_IX_DISP 
  294. cEnd <nogen>
  295. cProc Convert_Common,<FAR>
  296. cBegin
  297. SHR AL,1 ; convert AL = 4 or 8 to AL = 0 or 2
  298. SHR AL,1
  299. AND AL,0FEH
  300. ADD BL,AL ; add offset to dispatch table start
  301. CALL CS:[BX] ; call appropriate mathpack routine
  302. OR AX,AX ; Overflow?
  303. JZ Convert_done ; Jump if not
  304. JMP B$ERR_OV ; Else declare error
  305. Convert_done:
  306. cEnd
  307. sEnd _TEXT
  308. sBegin ST_TEXT
  309. assumes CS,ST_TEXT
  310. ;***
  311. ;B$MCVS - CVSMBF function
  312. ;
  313. ;Purpose:
  314. ; Given a string containing a 4-byte s.p. number in Microsoft Binary Format,
  315. ; return a pointer to an s.p. number in IEEE format.
  316. ;
  317. ;Entry:
  318. ; sdNum - string descriptor for the 4-byte string
  319. ;
  320. ;Exit:
  321. ; [AX] = pointer to resulting number in FAC.
  322. ;
  323. ;Uses:
  324. ; Per convention
  325. ;******************************************************************************
  326. cProc B$MCVS,<PUBLIC,FAR,NODATA>
  327. cBegin <nogen>
  328. MOV CL,4
  329. SKIP 2
  330. cEnd <nogen>
  331. ;***
  332. ;B$MCVD - CVDMBF function
  333. ;
  334. ;Purpose:
  335. ; Given a string containing a 8-byte d.p. number in Microsoft Binary Format,
  336. ; return a pointer to an d.p. number in IEEE format.
  337. ;
  338. ;Entry:
  339. ; sdNum - string descriptor for the 4-byte string
  340. ;
  341. ;Exit:
  342. ; [AX] = pointer to result in DAC
  343. ;
  344. ;Uses:
  345. ; Per convention
  346. ;******************************************************************************
  347. cProc B$MCVD,<PUBLIC,FAR,NODATA>
  348. cBegin <nogen>
  349. MOV CL,8
  350. XOR CH,CH
  351. cEnd <nogen>
  352. cProc BMCV_Real,<FAR,NODATA>,<ES,SI,DI> 
  353. parmSD sdNum
  354. cBegin
  355. MOV SI,OFFSET DGROUP:B$DAC
  356. GetpSD BX,sdNum ;BX = psdNum
  357. MOV DI,OFFSET DGROUP:b$Buf3 ; temporary storage (>= 8 bytes)
  358. PUSH CX ;Save the byte count
  359. CALL STRCPY ;copy data to $FTMP, delete string if temp
  360. POP AX ;[AX] = count of bytes
  361. XCHG SI,DI ;SI points to B$FTMP1 (input number)
  362. PUSH DS
  363. POP ES ;ES = DS for math format mapping call
  364. PUSH DI ;save pointer to result for retval
  365. CALL Ix_Mx ; perform actual conversion
  366. POP AX ;restore pointer to converted number in DAC
  367. cEnd
  368. ;***
  369. ;B$FMDF - MKDMBF$ function
  370. ;
  371. ;Purpose:
  372. ; Given an 8-byte d.p. number in IEEE format, return a pointer to
  373. ; an sd containing the d.p. number in Microsoft Binary Format.
  374. ;
  375. ;Entry:
  376. ; R8parm - a d.p. number
  377. ;
  378. ;Exit:
  379. ; [AX] = pointer to a string descriptor
  380. ;
  381. ;Uses:
  382. ; Per convention
  383. ;******************************************************************************
  384. cProc B$FMDF,<PUBLIC,FAR,NODATA> ;[6][3]
  385. parmQ R8parm
  386. cBegin
  387. MOV BX,8 ; 8 Bytes in d.p. # (required string size)
  388. LEA AX,R8parm
  389. CALL MK_MBF_SHARED
  390. cEnd
  391. ;***
  392. ;B$FMSF - MKSMBF$ function
  393. ;
  394. ;Purpose:
  395. ; Given a 4-byte s.p. number in IEEE format, return a pointer to
  396. ; an sd containing the s.p. number in Microsoft Binary Format.
  397. ;
  398. ;Entry:
  399. ; R4parm - a s.p. number
  400. ;
  401. ;Exit:
  402. ; [AX] = pointer to a string descriptor
  403. ;
  404. ;Uses:
  405. ; Per convention
  406. ;******************************************************************************
  407. cProc B$FMSF,<PUBLIC,FAR,NODATA> ;[6][3]
  408. parmD R4parm
  409. cBegin
  410. MOV BX,4 ; 4 Bytes in s.p. # (required string size)
  411. LEA AX,R4parm
  412. CALL MK_MBF_SHARED
  413. cEnd
  414. cProc MK_MBF_SHARED,<NEAR>,<ES,SI,DI> ;[6]
  415. cBegin
  416. XCHG AX,SI ; DS:SI = source address
  417. PUSH BX ; save size of number
  418. CALL B$STALCTMP ;allocate temp string; DX points to data area
  419. MOV DI,DX ;DI = target address
  420. PUSH DS
  421. POP ES ;ES:DI = target address
  422. POP CX ; restore size of number
  423. PUSH BX ;save address of string descriptor (for retval)
  424. CALL Mx_Ix ; do the actual conversion
  425. POP AX ;restore pointer to string descriptor
  426. cEnd
  427. sEnd ST_TEXT
  428. END