home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / loop.asm < prev    next >
Assembly Source File  |  1994-03-04  |  3KB  |  49 lines

  1. Date: Friday, 14 August 1987  04:43-MDT
  2. From: Ya'akov_Miles%UBC.MAILNET at MIT-Multics.ARPA
  3. To:   Info-IBMPC at C.ISI.EDU
  4. Re:   Re INFO-IBMPC Digest 30 Efficient Block Transfers
  5.  
  6. Title   Loop
  7. ;Demonstrate Block Transfer technique, sometimes called Transfer Vectoring
  8. COUNT           =12345                  ; Number of bytes to read
  9. BLOCK_SIZE      =9                      ; Bytes per data transfer block
  10. PORT            =241h                   ; Clock.  BCD seconds/100. (341h ?)
  11. ;
  12. BLOCK_SIZE      =BLOCK_SIZE and 0FFFEh  ; Force even # of bytes/xfer block
  13. ;
  14. Code    Segment                         ; Declare Segment before "Assume"
  15. Assume  ds:Code,ss:Code,cs:Code,es:Code ; Segment order avoids "problems"...
  16.         ORG     0100h                   ; Start address for .COM binary file
  17. begin:  mov     di,offset DATA          ; ES:[DI] --> data area
  18.         mov     cx,COUNT                ; Get total bytes to transfer
  19.         mov     bx,BLOCK_SIZE           ; Get data transfer block size, BYTES
  20.         mov     ax,cx                   ; Get lo order transfer byte count
  21.         xor     dx,dx                   ;  ...zero hi order byte count
  22.         div     bx                      ; AX = blocks, DX = remainder
  23.         push    ax                      ;  ...save block count
  24.         mov     cx,dx                   ; Get bytes in partial block
  25.         mov     dx,PORT                 ;  ...load clock port
  26.         jcxz    exact                   ; Exact number of blocks in transfer
  27. ;
  28. fract:  in      al,dx                   ; Read BCD seconds/hundred.
  29.         stosb                           ;  ...ES:[DI] --> (next) saved result
  30.         loop    fract                   ;  ...until done
  31. ;
  32. exact:  pop     cx                      ; Load number of blocks to transfer
  33.         jcxz    done                    ;  ...less than one block in xfer
  34. ;
  35. block:  Rept    BLOCK_SIZE/2            ; Unroll DO loop this amount, bytes
  36.         in      al,dx                   ; Read BCD seconds/hundred
  37.         xchg    ah,al                   ;  ...save temporary in register
  38.         in      al,dx                   ; Read BCD seconds/hundred
  39.         xchg    ah,al                   ;  ...swap bytes to IBM order. Yuk
  40.         stosw                           ;  ...ES:[DI] --> (next) saved result
  41.         Endm                            ;  ...end of unrolled DO loop
  42.         loop    block                   ;  ...love FORTRAN
  43. ;
  44. done:   ret                             ; Back to BASIC programming
  45. data:                                   ;  ...data area after program
  46. Code    ends
  47. ;
  48. End     Begin
  49.