home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / TASMEXMP.ZIP / VAREXCH.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  1.6 KB  |  46 lines

  1. ; Turbo Assembler    Copyright (c) 1988, 1991 By Borland International, Inc.
  2.  
  3. ; VAREXCH.ASM
  4.  
  5. ; From the Turbo Assembler Users Guide
  6.  
  7. CODE      SEGMENT
  8.           ASSUME cs:CODE,ds:NOTHING
  9.  
  10. ; Parameters (note that offset are +2 because of push bp)
  11.  
  12. var1      EQU    DWORD PTR ss:[bp+12]
  13. var2      EQU    DWORD PTR ss:[bp+8]
  14. count     EQU    WORD PTR  ss:[bp+6]
  15.  
  16.  
  17. Exchange  PROC FAR
  18.           PUBLIC Exchange
  19.           cld                        ;exchange goes upward
  20.           mov     dx,ds              ;save DS
  21.           push    bp
  22.           mov     bp,sp              ;get stack base
  23.           lds     si,var1            ;get first address
  24.           les     di,var2            ;get second address
  25.           mov     cx,count           ;get number of bytes to move
  26.           shr     cx,1           ;get word count (low bit -> carry)
  27.           jnc     ExchangeWords  ;if no odd byte, enter loop
  28.           mov     al,es:[di]     ;read odd byte from var2
  29.           movsb                  ;move a byte from var1 to var2
  30.           mov     [si-1],al      ;write var2 byte to var1
  31.           jz      Finis          ;done if only 1 byte to exchange
  32. ExchangeWords:
  33.           mov     bx,-2          ;BX is a handy place to keep -2
  34. ExchangeLoop:
  35.           mov     ax,es:[di]         ;read a word from var2
  36.           movsw                      ;do a move from var1 to var2
  37.           mov     [bx][si],ax        ;write var2 word to var1
  38.           loop    ExchangeLoop       ;repeat "count div 2" times
  39. Finis:
  40.           mov     ds,dx              ;get back Turbo's DS
  41.           pop     bp
  42.           ret     10
  43. Exchange  ENDP
  44. CODE      ENDS
  45.           END
  46.