home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / bluebook / asm-subr / mbinmul < prev    next >
Encoding:
Text File  |  1985-12-28  |  2.8 KB  |  99 lines

  1. ;-------------------------mbinmul routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 120
  4. ;
  5. ; NAME  MBINMUL
  6. ;
  7. ; ROUTINE FOR Multidigit Binary Multiplication
  8. ;
  9. ; FUNCTION: This routine multiplies two multidigit binary numbers.
  10. ;
  11. ; INPUT: Upon entry DS:SI points to the first number; DS:DI points to
  12. ; the second number, and DS:BX points to the location where the result
  13. ; will be stored.  The size of these multidigit numbers is controlled
  14. ; by the constant ISIZE.  The input numbers contain 16*ISIZE number of
  15. ; bits and the output number has double that precision.  Both inputs are
  16. ; stored in ISIZE number of 16-bit words of memory and the output is
  17. ; stored in 2*ISIZE number of 16-bit words of memory.
  18. ;
  19. ; OUTPUT: Upon exit DS:BX points to where the result is stored.
  20. ;
  21. ; REGISTERS USED:  No registers are modified.
  22. ;
  23. ; SEGMENTS REFERENCED:  Upon entry the data segment must contain
  24. ; storage for three multidigit numbers; two for input and one for output.
  25. ;
  26. ; ROUTINES CALLED:  None
  27. ;
  28. ; SPECIAL NOTES: None
  29. ;
  30. ; ROUTINE TO MULTIPLY MULTIDIGIT BINARY NUMBERS
  31. ;
  32. mbinmul    proc    far
  33. ;
  34.     push    si        ; save registers
  35.     push    di
  36.     push    bx
  37.     push    cx
  38.     push    ax
  39. ;
  40. ; clear result buffer
  41.     push    bx        ; save result pointer BX
  42.     mov    ax,0        ; get a zero
  43.     mov    cx,2*isize    ; double precision for this number
  44.     cld            ; forward direction
  45. ;
  46. mbinmul1:
  47.     mov    [bx],ax        ; clear the 'digit'
  48.     inc    bx        ; point to next 'digit'
  49.     inc    bx
  50.     loop    mbinmul1    ; loop through all 'digitts'
  51.     pop    bx        ; store result pointer BX
  52. ;
  53.     mov    cx,isize    ; get the number of 16-bit 'digits'
  54. ;
  55. mbnimul2:
  56.     push    cx        ; save counter from outter loop
  57.     mov    dx,[si]        ; get 'digit'' from 1st number
  58.     inc    si        ; point to next number
  59.     inc    si
  60. ;
  61.     push    bx        ; save register during inner loop
  62.     push    di
  63. ;
  64.     mov    cx,isize    ; get the number of 16-bit 'digits'
  65. ;
  66. mbinmul3:
  67.     push    cx        ; save counter for inner loop
  68.     push    dx        ; save multiplier digit
  69.     mov    ax,[di]        ; get 'digit' from 2nd number
  70.     inc    di        ; point to next 'digit'
  71.     inc    di
  72.     mul    dx        ; multiply
  73.     add    [bx],ax        ; add lower 'digit' to result
  74.     inc    bx        ; point to next 'digit'
  75.     inc    bx
  76.     adc    [bx],dx        ; add upper part to result
  77.     pop    dx        ; restore multiplier
  78.     pop    cx        ; restore counter for inner loop
  79.     loop    mbinmul3    ; loop through all 'digits' of second
  80. ;
  81.     pop    di        ; restore registers
  82.     pop    bx
  83. ;
  84.     inc    bx        ; shift by on 'digit'
  85.     inc    bx
  86.     pop    cx        ; restore counter for outer loop
  87.     loop    mbinmul2    ; loop through all 'digits' of first
  88. ;
  89.     pop    ax        ; restore registers
  90.     pop    cx
  91.     pop    bx
  92.     pop    di
  93.     pop    si
  94.     ret
  95. ;
  96.     ret            ; return
  97. ;
  98. mbinmul    endp
  99. ;-------------------------mbinmul routine ends---------------------------