home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 137_01 / llint.asm < prev    next >
Assembly Source File  |  1985-03-10  |  8KB  |  378 lines

  1. ;
  2. ; llint.asm
  3. ;
  4. ; version of 25-Mar-84
  5. ;
  6. ; a component of lsup.c
  7. ;
  8. ; Copyright 1984 (c) A. Skjellum. All rights reserved.
  9. ; these routines are setup for Aztec C86 v 1.05i
  10. ;
  11. ; all procedures are "near"
  12. ;
  13.  
  14. dseg    segment para public 'data'
  15. dseg    ends
  16.  
  17. cseg    segment para public 'code'
  18.     assume    cs:cseg,ds:dseg,es:dseg,ss:dseg
  19.  
  20. ;
  21. ; Routines which do not merit calls to portable routines in llsup.asm
  22. ;
  23.  
  24. ;
  25. ; ds = flptr(lptr,sptr)
  26. ; LPTR *lptr;
  27. ; char *sptr;
  28. ;
  29. ; form a long pointer from a "normal" ds relative short pointer (sptr)
  30. ; and store at lptr
  31. ;
  32. ; note: no portable segment (flptr) in llsup.asm since this
  33. ; is such a trivial routine.
  34. ;
  35. ; return value is also ds, should this prove useful
  36. ;
  37.     public    flptr_
  38. flptr_    proc    near
  39.     mov    bx,sp        ; prepare for argument load
  40.     mov    ax,4[bx]    ; get short pointer ds:ax
  41.     mov    bx,2[bx]    ; get address where to store long pointer
  42.     mov    [bx],ax        ; store low order
  43.     mov    ax,ds
  44.     mov    2[bx],ax    ; store high order
  45.     ret            ; return value is also ds
  46. flptr_    endp
  47.  
  48. ;
  49. ; the following four routines are examples of what can
  50. ; be done to supplement general routines with specific
  51. ; (more efficient ones).  Many more variations are
  52. ; possible than the two presented here.  They follow
  53. ; directly from this basic idea:
  54. ;
  55. ;
  56. ; char lchr(lptr)
  57. ; LPTR *lptr;
  58. ;
  59. ; return character pointed to by lptr
  60. ;
  61.     public    lchr_
  62. lchr_    proc    near
  63.     mov    bx,sp        ; prepare for argument load
  64.     push    ds        ; save ds register
  65.     mov    bx,2[bx]    ; get address of lptr
  66.     mov    ax,[bx]        ; 
  67.     mov    ds,2[bx]    ; begin forming pointer
  68.     mov    bx,ax        ; ds:bx now is valid pointer
  69.     sub    ax,ax        ; zero whole acc.
  70.     mov    al,[bx]        ; get the character
  71.     pop    ds
  72.     ret            ; exit with char in ax
  73. lchr_    endp
  74.  
  75. ;
  76. ; int lint(lptr)
  77. ; LPTR *lptr;
  78. ; return integer or unsigned pointed to by lptr
  79. ;
  80.     public    lint_
  81. lint_    proc    near
  82.     mov    bx,sp        ; prepare for argument load
  83.     push    ds        ; save ds register
  84.     mov    bx,2[bx]    ; get address of lpr
  85.     mov    ax,[bx]        ; 
  86.     mov    ds,2[bx]    ; begin forming pointer
  87.     mov    bx,ax        ; ds:bx now is valid pointer
  88.     mov    ax,[bx]        ; get the integer or unsigned
  89.     pop    ds        ; recover old ds value
  90.     ret            ; and exit with char in ax
  91. lint_    endp
  92.  
  93. ;
  94. ; l_stchr(lptr,chr)
  95. ; LPTR *lptr;
  96. ; char chr;
  97. ;
  98. ; store character chr at address lptr
  99. ;
  100.     public    l_stchr_
  101. l_stchr_ proc    near
  102.     mov    bx,sp        ; prepare for argument load
  103.     mov    cl,4[bx]    ; get character
  104.     mov    bx,2[bx]    ; prepare for load of long pointer
  105.     push    ds        ; save ds segment register
  106.     mov    ax,[bx]        ; 
  107.     mov    ds,2[bx]    ; begin forming pointer
  108.     mov    bx,ax        ; ds:bx now is valid pointer
  109.     mov    [bx],cl        ; store byte
  110.     pop    ds
  111.     ret
  112. l_stchr_ endp
  113.  
  114. ;
  115. ; l_stint(lptr,val)
  116. ; LPTR *lptr;
  117. ; int val;
  118. ;
  119. ; store integer or unsigned at address lptr
  120. ;
  121.     public    l_stint_
  122. l_stint_ proc    near
  123.     mov    bx,sp        ; prepare for argument load
  124.     mov    cx,4[bx]    ; get integer to store
  125.     mov    bx,2[bx]    ; prepare to form ds:bx with correct
  126.                 ; storage address
  127.     push    ds        ; save current ds
  128.     mov    ax,[bx]        ; 
  129.     mov    ds,2[bx]    ; begin forming pointer
  130.     mov    bx,ax        ; ds:bx now is valid pointer
  131.     mov    [bx],cx        ; store the integer
  132.     pop    ds
  133.     ret            ; exit 
  134. l_stint_ endp
  135.  
  136. ;
  137. ; lload(dest,lptr,len)
  138. ; char *dest;
  139. ; LPTR *lptr;
  140. ; unsigned len;
  141. ;
  142. ; general purpose copy routine from long data storage to ds: relative
  143. ; storage
  144. ;
  145. ; we assume es = ds for Aztec C explicitly here
  146. ;
  147. ; due to convenient 8086 instructions, the portable function would
  148. ; consist merely of a "cld", "rep movsb" sequence followed by a return.
  149. ; Therefore, no portable lload is included in llsup.asm
  150. ;
  151.  
  152.     public    lload_
  153. lload_    proc    near
  154.     mov    bx,sp        ; prepare for argument load
  155.     push    ds        ; save Aztec ds segment
  156.     push    si
  157.     push    di        ; save source and destination indices
  158.     ;
  159.     mov    cx,6[bx]    ; get length for move
  160.     mov    di,2[bx]    ; es:di now has the destination address
  161.     mov    bx,4[bx]    ; prepare to load long ptr
  162.     mov    si,[bx]        ; get low order
  163.     mov    ds,2[bx]    ; and then high order
  164.     cld
  165.     rep    movsb        ; do the move
  166.     pop    di
  167.     pop    si
  168.     pop    ds
  169.     ret
  170. lload_    endp
  171.  
  172. ;
  173. ; lstor(lptr,src,len)
  174. ; LPTR *lptr;
  175. ; char *src;
  176. ; unsigned len;
  177. ;
  178. ; Reverse of lload: this routine copies data from ds:src to lptr
  179. ; Once again, there is no llsup analog.
  180. ;
  181.     public    lstor_
  182. lstor_    proc    near
  183.     mov    bx,sp        ; prepare for argument load
  184.     push    es
  185.     push    di
  186.     push    si        ; save registers as required by Aztec C.
  187.     mov    cx,6[bx]    ; get length of move
  188.     mov    si,4[bx]    ; ds:si now contains source index
  189.     mov    bx,2[bx]    ; prepare to form es:di
  190.     mov    di,[bx]
  191.     mov    es,2[bx]
  192.     rep    movsb        ; move the data
  193.     pop    si
  194.     pop    di
  195.     pop    es
  196.     ret            ; restore registers and exit
  197. lstor_    endp
  198.  
  199. ;
  200. ; -----------------------------------------------------
  201. ;
  202. ; routines which call portable subroutines in llsup.asm
  203. ;
  204. ; -----------------------------------------------------
  205. ;
  206. ; linc(lptr)
  207. ; LPTR *lptr;
  208. ;
  209. ; increment a long pointer by 1
  210. ;
  211.     public    linc_
  212. linc_    proc    near
  213.     extrn    linc:near
  214.     mov    bx,sp        ; prepare for argument load
  215.     push    es        ; save es value from caller
  216.     mov    bx,2[bx]
  217.     push    bx        ; address where answer will go
  218.     mov    es,2[bx]    ; get segment
  219.     mov    bx,[bx]        ; and address
  220.     call    linc        ; do the work
  221.     pop    ax
  222.     xchg    ax,bx
  223.     mov    [bx],ax
  224.     mov    2[bx],es    ; store the value
  225.     pop    es        ; recover the old value
  226.     ret            ; and exit
  227. linc_    endp
  228.  
  229. ;
  230. ; ldec(lptr)
  231. ; LPTR *lptr;
  232. ;
  233. ; decrement a long pointer by 1
  234. ;
  235.     public    ldec_
  236. ldec_    proc    near
  237.     extrn    ldec:near
  238.     mov    bx,sp        ; prepare for argument load
  239.     push    es        ; preserve es
  240.     mov    bx,2[bx]    ; get address ds:bx
  241.     push    bx        ; address where answer will go
  242.     mov    ax,[bx]        ;
  243.     mov    es,2[bx]
  244.     mov    bx,ax
  245.     call    ldec        ; do the decrement
  246.     pop    ax
  247.     xchg    ax,bx
  248.     mov    [bx],ax
  249.     mov    2[bx],es    ; store the value
  250.     pop    es        ; recover it for sake of caller
  251.     ret            ; and then exit
  252. ldec_    endp
  253.  
  254. ;
  255. ; ladd(lptr,offset)
  256. ; LPTR *lptr;
  257. ; unsigned offset;
  258. ;
  259. ; add unsigned offset to a long pointer
  260. ;
  261.     public    ladd_
  262. ladd_    proc    near
  263.     extrn    ladd:near
  264.     mov    bx,sp        ; prepare for argument load
  265.     push    es        ; save es value of caller
  266.     mov    ax,4[bx]    ; get the offset to ax
  267.     mov    bx,2[bx]
  268.     push    bx        ; address where answer will go too.
  269.     mov    cx,[bx]
  270.     mov    es,2[bx]
  271.     mov    bx,cx
  272.     call    ladd        ; do the addition
  273.     pop    ax
  274.     xchg    ax,bx
  275.     mov    [bx],ax
  276.     mov    2[bx],es    ; store the value
  277.     pop    es        ; recover old es value
  278.     ret            ; and then exit
  279. ladd_    endp
  280.  
  281. ;
  282. ; lsub(lptr,offset)
  283. ; LPTR *lptr;
  284. ; unsigned offset;
  285. ;
  286. ; subtract unsigned offset from a long pointer
  287. ;
  288.     public    lsub_
  289. lsub_    proc    near
  290.     extrn    lsub:near
  291.     mov    bx,sp        ; prepare for argument load
  292.     push    es        ; preserve es 
  293.     mov    ax,4[bx]    ; get the offset
  294.     mov    bx,2[bx]
  295.     push    bx        ; store answer at this addr. too.
  296.     mov    cx,[bx]
  297.     mov    es,2[bx]
  298.     mov    bx,cx
  299.     call    lsub        ; do the subtraction
  300.     pop    ax
  301.     xchg    ax,bx
  302.     mov    [bx],ax
  303.     mov    2[bx],es    ; store the value
  304.     pop    es        ; restore es
  305.     ret            ; and then exit
  306. lsub_    endp
  307.  
  308. ;
  309. ; lsum(lptr,offset)
  310. ; LPTR *lptr;
  311. ; int offset;
  312. ;
  313. ; add signed offset to a long pointer
  314. ;
  315.     public    lsum_
  316. lsum_    proc    near
  317.     extrn    lsum:near
  318.     mov    bx,sp        ; prepare for argument load
  319.     push    es        ; preserve caller's es
  320.     mov    ax,4[bx]    ; get the signed offset
  321.     mov    bx,2[bx]
  322.     push    bx
  323.     mov    cx,[bx]
  324.     mov    es,2[bx]
  325.     mov    bx,cs
  326.     call    lsum        ; do the signed addition
  327.     pop    ax
  328.     xchg    ax,bx
  329.     mov    [bx],ax
  330.     mov    2[bx],es    ; store the value
  331.     pop    es        ;
  332.     ret            ; exit.
  333. lsum_    endp
  334.  
  335. ;
  336. ; lcopy(dest,src,len)
  337. ; LPTR *dest;
  338. ; LPTR *src;
  339. ; long len;    (treated as a long unsigned quantity)
  340. ;
  341. ;     copy from src to dest, len bytes.
  342. ;
  343. ; note this routine can be used to copy arbitrarily large chunks of memory
  344. ;
  345.     public    lcopy_
  346. lcopy_    proc    near
  347.     extrn    lcopy:near
  348.     mov    bx,sp        ; prepare for argument load
  349.     push    ds
  350.     push    es        ; save segment registers
  351.     push    di
  352.     push    si        ; save these registers for Aztec C
  353.     ;
  354.     mov    cx,6[bx]    ; get length (low order)
  355.     mov    dx,8[bx]    ; high order of length
  356.     mov    ax,2[bx]    ; get ds:ax as pointer to dest.
  357.     xchg    ax,bx
  358.     mov    di,[bx]
  359.     mov    es,2[bx]
  360.     mov    bx,ax
  361.     mov    bx,4[bx]    ; get ds:bx as pointer for dest.
  362.     mov    si,[bx]
  363.     mov    ds,2[bx]    ; get long pointer
  364.     ;
  365.     call    lcopy
  366.     ;
  367.     pop    si
  368.     pop    di
  369.     pop    es
  370.     pop    ds
  371.     ret
  372. lcopy_    endp    
  373.  
  374. cseg    ends
  375.     end
  376.