Assembly Language Help (alang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
MulLong
◄Map► ◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
;* MulLong - Multiplies two unsigned double-word (long) integers. The
;* procedure allows for a product of twice the length of the multipliers,
;* thus preventing overflows. The result is copied into a 4-word data area
;* and a pointer to the data area is returned.
;*
;* Shows: Instruction - mul
;* Predefined equate - @data
;*
;* Params: Long1 - First integer (multiplicand)
;* Long2 - Second integer (multiplier)
;*
;* Return: Pointer to quadword result
.DATA
PUBLIC result
result QWORD WORD PTR ? ; Result from MulLong
.CODE
MulLong PROC,
Long1:DWORD, Long2:DWORD
mov ax, WORD PTR Long2[2] ; Multiply long2 high word
mul WORD PTR Long1[2] ; by long1 high word
mov WORD PTR result[4], ax
mov WORD PTR result[6], dx
mov ax, WORD PTR Long2[2] ; Multiply long2 high word
mul WORD PTR Long1[0] ; by long1 low word
mov WORD PTR result[2], ax
add WORD PTR result[4], dx
adc WORD PTR result[6], 0 ; Add any remnant carry
mov ax, WORD PTR Long2[0] ; Multiply long2 low word
mul WORD PTR Long1[2] ; by long1 high word
add WORD PTR result[2], ax
adc WORD PTR result[4], dx
adc WORD PTR result[6], 0 ; Add any remnant carry
mov ax, WORD PTR Long2[0] ; Multiply long2 low word
mul WORD PTR Long1[0] ; by long1 low word
mov WORD PTR result[0], ax
add WORD PTR result[2], dx
adc WORD PTR result[4], 0 ; Add any remnant carry
mov ax, OFFSET result ; Return pointer
mov dx, @data ; to result
ret
MulLong ENDP
-♦-