home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / zendisk2.zip / LST13-4.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  638b  |  47 lines

  1. ;
  2. ; *** Listing 13-4 ***
  3. ;
  4. ; Negates several 32-bit values with non-branching code.
  5. ;
  6.     jmp    Skip
  7. ;
  8. ; Negates a 32-bit value.
  9. ;
  10. ; Input:
  11. ;    DX:AX = 32-bit value to negate
  12. ;
  13. ; Output:
  14. ;    DX:AX = negated 32-bit value
  15. ;
  16. ; Registers altered: AX, DX
  17. ;
  18. Negate32Bits:
  19.     neg    dx
  20.     neg    ax
  21.     sbb    dx,0
  22.     ret
  23. ;
  24. Skip:
  25.     call    ZTimerOn
  26. ; First, negate zero.
  27.     sub    dx,dx
  28.     mov    ax,dx    ;0
  29.     call    Negate32Bits
  30. ; Next, negate 1 through 50.
  31. X=1
  32.     rept    50
  33.     sub    dx,dx
  34.     mov    ax,X
  35.     call    Negate32Bits
  36. X=X+1
  37.     endm
  38. ; Finally, negate -1 through -50.
  39. X=-1
  40.     rept    50
  41.     mov    dx,0ffffh
  42.     mov    ax,X
  43.     call    Negate32Bits
  44. X=X-1
  45.     endm
  46.     call    ZTimerOff
  47.