home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol8n20.zip / MPNEG.ASM < prev    next >
Assembly Source File  |  1989-10-13  |  2KB  |  52 lines

  1.         title   MPNEG.ASM Multiple-Precision 2's Complement
  2.         page    55,132
  3.  
  4. ; MPNEG.ASM     Multiple-Precision 2's Complement Routine
  5. ;               for Intel 8086, 8088, 80286, and
  6. ;               80386 in real mode/16-bit protected mode
  7. ;
  8. ; Copyright (C) 1989 Ziff Davis Communications
  9. ; PC Magazine * Ray Duncan
  10. ;
  11. ; Call with:    DS:SI   = address of argument
  12. ;               CX      = argument length in bytes
  13. ;               Assumes direction flag is clear at entry
  14. ;
  15. ; Returns:      ES:DI   = address of result
  16. ;
  17. ; Destroys:     Nothing
  18.  
  19. _TEXT   segment word public 'CODE'
  20.  
  21.         assume  cs:_TEXT
  22.  
  23.         public  mpneg
  24. mpneg   proc    near
  25.  
  26.         mov     di,si                   ; save address of result
  27.         push    cx                      ; save two copies of 
  28.         push    cx                      ; argument length
  29.  
  30. mpneg1: not     byte ptr [si]           ; 1's complement this digit
  31.         inc     si                      ; advance through argument
  32.         loop    mpneg1                  ; until all digits inverted
  33.  
  34.         pop     cx                      ; retrieve length of argument
  35.         mov     si,di                   ; retrieve first-byte-address
  36.         stc                             ; set carry to add 1
  37.  
  38. mpneg2: adc     byte ptr [si],0         ; add 1 to 1's complement
  39.         inc     si                      ; to get 2's complement
  40.         loop    mpneg2                  ; until all digits finished
  41.  
  42.         pop     cx                      ; restore operand length
  43.         mov     si,di                   ; restore argument address
  44.         ret                             ; back to caller
  45.  
  46. mpneg   endp
  47.  
  48. _TEXT   ends
  49.  
  50.         end
  51.  
  52.