home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 3 / FREEWARE.BIN / ms_dos / dsort / asmutys.pre < prev    next >
Text File  |  1980-01-02  |  9KB  |  314 lines

  1.     page    96,132
  2. ;§∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞§
  3. ;§                                                                          §
  4. ;§              ディレクトリエントリ  ソート  ユーティリティ                §
  5. ;§                                                                          §
  6. ;§                                     DSORT.EXE  Ver1.11    §
  7. ;§                                                                          §
  8. ;§                   Copyright (C) by 福地 邦雄 1991. All rights reserved.  §
  9. ;§∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞§
  10.     .MODEL  SMALL,C
  11.     .data
  12. ;
  13.     public  errorno         ;プログラム終了時のステータスに指定する
  14. errorno     dw      ?           ;エラーコード
  15. ;
  16. printmsg    db  'print error',0dh,0ah   ;標準プリントのエラー表示のメッセージ
  17. prtmsgsiz   equ     $-printmsg
  18. ;
  19. allocmsg    db  'memory allocation error',0dh,0ah   ;メモリ獲得エラーの
  20. alcmsgsiz   equ     $-allocmsg              ;メッセージ
  21. ;
  22.     .code
  23. ;
  24. ;------------------------------------------------------------------------------
  25. ;
  26. ;   getargs
  27. ;       コマンドライン入力を分解してポインタのリストにする
  28. ;       空白,タブを区切り文字とする   プログラム名はサポートされない
  29. ;
  30. ;   TYPE    near call
  31. ;   IN  ds=psp
  32. ;       200h以上のスタックサイズ
  33. ;   OUT ss:bp にファーポインタリストの先頭アドレス
  34. ;       ax に文字列の個数       ゼロフラグに個数のテスト結果
  35. ;       ディレクションフラグ ダウン方向
  36. ;
  37. ;   保存レジスタ    ds のみ
  38. ;
  39. ;------------------------------------------------------------------------------
  40. ;
  41. stackwrk    equ 01c0h
  42. argcwrk     equ word ptr [bp]
  43. returnaddr  equ word ptr [bp+2]
  44. strings     equ word ptr [bp+4]
  45. cmdlen      equ ds:[80h]
  46. cmdtop      equ 81h
  47. SPC     equ 20h
  48. TAB     equ 09h
  49. ;
  50.     public  getargs
  51. getargs proc    near
  52. ;
  53.     sub     sp,stackwrk     ;文字列とポインタリスト領域の確保
  54.     mov     bp,sp
  55.     mov     ax,[bp+stackwrk]    ;リターンアドレスのセーブ
  56.     mov     returnaddr,ax
  57.     xor     ax,ax           ;ワーク領域&レジスタの初期化
  58.     mov     argcwrk,ax
  59.     mov     cx,ax
  60.     lea     di,strings
  61.     mov     cl,cmdlen       ;コマンドライン文字列長の取得
  62.     mov     si,cx
  63.     inc     cx
  64.     mov     bx,cmdtop
  65.     mov     byte ptr [si+bx],SPC    ;コマンドライン終端の改行コードを空白に
  66. ;
  67. spaceloop:              ;空白,タブをスキップする
  68.     cmp     byte ptr [bx],SPC
  69.     je      nextchar
  70.     cmp     byte ptr [bx],TAB
  71.     jne     spaceout
  72. nextchar:
  73.     inc     bx
  74.     loop    spaceloop
  75.     jmp     argend
  76. ;
  77. spaceout:               ;
  78.     mov     ss:[di],bx      ;文字列の先頭オフセットのセーブ
  79.     mov     word ptr ss:[di+2],0    ;文字列長さ初期化
  80.     lea     di,[di+4]
  81.     inc     argcwrk         ;文字列個数のカウントアップ
  82. nospcloop:
  83.     inc     word ptr ss:[di-2]  ;文字列長さのカウントアップ
  84.     dec     cx
  85.     jcxz    stringend
  86.     inc     bx
  87.     cmp     byte ptr [bx],SPC   ;空白,タブが現れるまでループ
  88.     je      stringend
  89.     cmp     byte ptr [bx],TAB
  90.     je      stringend
  91.     jmp     short nospcloop
  92. stringend:
  93.     mov     byte ptr [bx],0     ;文字列終端に 0 をセット
  94.     inc     bx
  95.     loop    spaceloop       ;空白,タブのスキップ
  96. ;
  97. argend:
  98.     mov     ax,argcwrk      ;文字列個数をチェック 0 なら終了
  99.     test    ax,ax
  100.     jnz     argsset
  101.     add     sp,stackwrk
  102.     xor     ax,ax
  103.     ret
  104. ;
  105. argsset:
  106.     mov     dx,di           ;文字列情報の最終アドレスをセーブ
  107.     mov     bx,di           ;
  108.     std             ;コピー方向=ダウンカウント
  109.     lea     di,[bp+stackwrk+1]  ;スタック最終アドレスを取得
  110.     @do until           ;文字列をスタックへコピー
  111.         lea     bx,[bx-4]
  112.         mov     cx,ss:[bx+2]        ;文字列長取得
  113.         mov     ss:[bx+2],ss        ;コピー後セグメントセット
  114.         mov     si,ss:[bx]      ;文字列終端アドレス取得
  115.         add     si,cx
  116.         inc     cx          ;終端文字分をカウントアップ
  117.         mov     es,ss:[bx+2]
  118.       rep   movsb
  119.         mov     ss:[bx],di      ;スタック上の文字列オフセット設定
  120.         inc     word ptr ss:[bx]
  121.         dec     ax
  122.     @doend (zf,on)
  123. ;                   ;ファーポインタリストのコピー
  124.     and     di,0fffeh       ;コピー先設定
  125.     lea     di,[di-2]
  126.     mov     cx,dx
  127.     mov     si,cx           ;コピー元設定
  128.     lea     si,[si-2]
  129.     sub     cx,bx
  130.     shr     cx,1            ;コピーカウント(ワード)設定
  131.     push    ds
  132.     mov     ds,ss:[si]      ;スタックセグメント取得
  133.   rep    movsw
  134.     pop     ds
  135. ;
  136.     mov     ax,argcwrk
  137.     mov     bx,returnaddr       ;リターンアドレス設定
  138.     mov     ss:[di],bx
  139.     lea     bp,[di+2]       ;ファーポインタリストのオフセット
  140.     mov     sp,di
  141.     test    ax,ax
  142.     ret
  143. ;
  144. getargs endp
  145. ;
  146. ;------------------------------------------------------------------------------
  147. ;
  148. ;   asctoint
  149. ;       アスキー10進数字列から、16ビットバイナリーへの変換
  150. ;       数字でない文字に出会った時点で終了する
  151. ;
  152. ;   TYPE    near call
  153. ;   IN  es:di アスキー10進数字列アドレス
  154. ;   OUT ax 変換した数値
  155. ;       es:di 変換時の数字でない文字のアドレス
  156. ;   保存レジスタ    bx,cx,dx,si,bp,ds,es
  157. ;
  158. ;------------------------------------------------------------------------------
  159. ;
  160.     public  asctoint
  161. asctoint    proc    uses bx cx dx
  162. ;
  163.     xor     ax,ax           ;変換中の数値&変換後通知データ
  164.     mov     cx,ax           ;獲得する(した)文字
  165.     mov     bx,10           ;10進変換のための乗数
  166.     @do repeat
  167.         mov     cl,es:[di]      ;文字獲得
  168.         @if (cl,<,'0'),or,(cl,>,'9')
  169.             @doexit
  170.         @ifend
  171.         and     cl,0fh          ;文字を数値に変換
  172.         mul     bx          ;今までの変換データを10倍
  173.         add     ax,cx           ;獲得した数値を加算
  174.         inc     di          ;次の文字位置へ
  175.     @doend
  176.     test    ax,ax           ;ゼロフラグ設定
  177.     ret
  178. ;
  179. asctoint    endp
  180. ;
  181. ;------------------------------------------------------------------------------
  182. ;
  183. ;   inttoasc0
  184. ;       16ビットバイナリをアスキー10進数字列に変換する
  185. ;       5 桁固定で 頭の 0 も出力する
  186. ;
  187. ;   TYPE    near call
  188. ;   IN  ax 16ビットバイナリ
  189. ;       es:di 変換後のアスキー10進数字列を格納するアドレス
  190. ;   OUT es:di 変換したアスキー10進数字列の次のアドレス
  191. ;   保存レジスタ    bx,cx,dx,si,bp,ds,es
  192. ;
  193. ;------------------------------------------------------------------------------
  194. ;
  195.     public  inttoasc0
  196. inttoasc0   proc    uses cx dx
  197. ;
  198.     cld             ;変換後文字列出力方向 アップ方向
  199.     mov     cx,100          ;10進変換のための除数
  200.     xor     dx,dx           ;32/16ビット除算用の上位16ビットクリア
  201.     div     cx          ;100で割る DX=余り AX=商
  202.     div     cl          ;商を更に100で割る AH=余り AL=商
  203.     add     al,'0'          ;万の位を数字文字に変換して出力
  204.     stosb
  205.     mov     al,ah           ;千,百の位を数字文字に変換して出力
  206.     aam
  207.     add     ax,'00'
  208.     xchg    ah,al
  209.     stosw
  210.     mov     al,dl           ;十,一の位を数字文字に変換して出力
  211.     aam
  212.     add     ax,'00'
  213.     xchg    ah,al
  214.     stosw
  215.     ret
  216. ;
  217. inttoasc0   endp
  218. ;
  219. ;------------------------------------------------------------------------------
  220. ;
  221. ;   dosstdout
  222. ;       MS-DOSのハンドル2番 標準出力へデータを出力する
  223. ;       エラーが起こった時はアボートする
  224. ;
  225. ;   TYPE    near call
  226. ;   IN  cx 出力データ長
  227. ;       ds:dx 出力データの先頭アドレス
  228. ;   OUT なし
  229. ;   保存レジスタ    si,di,bp,ds,es
  230. ;
  231. ;------------------------------------------------------------------------------
  232. ;
  233.     public  dosstdout
  234. dosstdout   proc
  235. ;
  236.     mov     ah,40h
  237.     mov     bx,1
  238.     int     21h
  239.     @if (cf,on)
  240.         mov     ah,4ch
  241.         int     21h
  242.     @ifend
  243.     ret
  244. ;
  245. dosstdout   endp
  246. ;
  247. ;------------------------------------------------------------------------------
  248. ;
  249. ;   dosallocx
  250. ;       MS-DOSのメモリ獲得を呼び出す、獲得出来ない時は標準出力へエラー
  251. ;       メッセージを出力してアボートする
  252. ;
  253. ;   TYPE    near call
  254. ;   IN  dx:ax 獲得したいメモリのバイトサイズ
  255. ;   OUT ax 割り当てられたメモリのセグメントアドレス
  256. ;   保存レジスタ    cx,si,di,bp,ds,es
  257. ;
  258. ;------------------------------------------------------------------------------
  259. ;
  260.     public  dosallocx
  261. dosallocx    proc   uses bx cx
  262. ;
  263.     mov     cl,4
  264.     add     ax,15
  265.     adc     dx,0
  266.     shr     ax,cl
  267.     and     dx,0fh
  268.     ror     dx,cl
  269.     mov     bx,ax
  270.     or      bx,dx
  271.     mov     ah,48h
  272.     int     21h
  273.     @if (cf,on)
  274.         mov     errorno,ax
  275.         mov     dx,offset allocmsg
  276.         mov     cx,alcmsgsiz
  277.         jmp     abort
  278.     @ifend
  279.     ret
  280. ;
  281. dosallocx    endp
  282. ;
  283. ;------------------------------------------------------------------------------
  284. ;
  285. ;   abort
  286. ;       標準出力へメッセージを出力した後、プログラム終了する
  287. ;       終了時に終了コードを設定する
  288. ;
  289. ;   TYPE    near call
  290. ;   IN  cx 出力データ長
  291. ;       ds(data):dx 出力データの先頭アドレス
  292. ;       ds(data):errorno 終了コード
  293. ;   OUT なし
  294. ;   保存レジスタ    si,di,bp,ds,es
  295. ;
  296. ;------------------------------------------------------------------------------
  297. ;
  298.     public  abort
  299. abort       proc
  300. ;
  301.     mov     ax,seg  _data
  302.     mov     ds,ax
  303.     mov     ah,40h
  304.     mov     bx,1
  305.     int     21h
  306. ;
  307.     mov     ax,errorno
  308.     mov     ah,4ch
  309.     int     21h
  310. ;
  311. abort       endp
  312. ;
  313.     end
  314.