From 84b7d0f1ab85b7795e1946a955d669ea0667b4d5 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Fri, 5 Sep 2014 10:49:10 +0200 Subject: [PATCH] [Reduction] #467: Far long multiplication Yeah, the code is identical to the near version, with the only difference being the PROC directive declaring the function as either near or far. Now, I could either turn the function body into some kind of macro stored in a separate file and then instantiate it from both near and far functions... or I could just copy the original structure. Who cares, anyway. --- libs/BorlandC/f_lxmul.asm | 62 +++++++++++++++++++++++++++++++++++++++ th01_fuuin.asm | 28 +----------------- th01_reiiden.asm | 28 +----------------- th02_op.asm | 28 +----------------- 4 files changed, 65 insertions(+), 81 deletions(-) create mode 100644 libs/BorlandC/f_lxmul.asm diff --git a/libs/BorlandC/f_lxmul.asm b/libs/BorlandC/f_lxmul.asm new file mode 100644 index 00000000..2ee82b89 --- /dev/null +++ b/libs/BorlandC/f_lxmul.asm @@ -0,0 +1,62 @@ +; *Not* the original file, but an edit to turn it into an includable slice. +; Changes include: +; * removal of RULES.ASI to eliminate redundancy +; * removal of the 'CODE' segment declaration (for obvious reasons) +; * the @@ prefix on any local labels + +;[]-----------------------------------------------------------------[] +;| F_LXMUL.ASM -- long multiply routine | +;[]-----------------------------------------------------------------[] + +; +; C/C++ Run Time Library - Version 5.0 +; +; Copyright (c) 1987, 1992 by Borland International +; All Rights Reserved. +; +; calls to this routine are generated by the compiler to perform +; long multiplications. + +; There is no check for overflow. Consequently, the same routine +; is used for both signed and unsigned long multiplies. + +; +; in: +; (dx:ax) - 32bit arg1 +; (cx:bx) - 32bit arg2 +; out: +; (dx:ax) - 32bit product +; +; reg use: bx,cx destroyed, all others preserved or contain result. +; +; hi(result) := lo(hi(arg1) * lo(arg2)) + +; lo(hi(arg2) * lo(arg1)) + +; hi(lo(arg1) * lo(arg2)) +; lo(result) := lo(lo(arg1) * lo(arg2)) +; +; + + public LXMUL@ + public F_LXMUL@ + +LXMUL@ PROC FAR +F_LXMUL@: + push si + xchg si,ax ; save lo1 + xchg ax,dx + test ax,ax ; skip mul if hi1==0 + jz @@nohi1 + mul bx ; hi1 * lo2 + +@@nohi1: ; if we jumped here, ax==0 so the following swap works + jcxz @@nohi2 ; skip mul if hi2==0 + xchg cx, ax ; result <-> hi2 + mul si ; lo1 * hi2 + add ax, cx ; ax = hi1*lo2 + hi2*lo1 +@@nohi2: + xchg ax,si + mul bx ; lo1 * lo2 + add dx,si ; hi order result += partials + pop si + ret +LXMUL@ ENDP diff --git a/th01_fuuin.asm b/th01_fuuin.asm index e3c87f3e..d3cd5515 100644 --- a/th01_fuuin.asm +++ b/th01_fuuin.asm @@ -3465,33 +3465,7 @@ __dos_setfileattr endp include libs/BorlandC/dosgdriv.asm include libs/BorlandC/errormsg.asm include libs/BorlandC/exit.asm - -; =============== S U B R O U T I N E ======================================= - -; Attributes: library function - -LXMUL@ proc far - push si - xchg ax, si - xchg ax, dx - test ax, ax - jz short loc_1F0F - mul bx - -loc_1F0F: - jcxz short loc_1F16 - xchg ax, cx - mul si - add ax, cx - -loc_1F16: - xchg ax, si - mul bx - add dx, si - pop si - retf -LXMUL@ endp - +include libs/BorlandC/f_lxmul.asm include libs/BorlandC/f_scopy.asm include libs/BorlandC/getvect.asm include libs/BorlandC/H_LDIV.ASM diff --git a/th01_reiiden.asm b/th01_reiiden.asm index c8ad0eab..4b0e1d12 100644 --- a/th01_reiiden.asm +++ b/th01_reiiden.asm @@ -4933,33 +4933,7 @@ __dos_setfileattr endp include libs/BorlandC/dosgdriv.asm include libs/BorlandC/errormsg.asm include libs/BorlandC/exit.asm - -; =============== S U B R O U T I N E ======================================= - -; Attributes: library function - -LXMUL@ proc far - push si - xchg ax, si - xchg ax, dx - test ax, ax - jz short loc_2749 - mul bx - -loc_2749: - jcxz short loc_2750 - xchg ax, cx - mul si - add ax, cx - -loc_2750: - xchg ax, si - mul bx - add dx, si - pop si - retf -LXMUL@ endp - +include libs/BorlandC/f_lxmul.asm include libs/BorlandC/f_scopy.asm include libs/BorlandC/getvect.asm include libs/BorlandC/H_LDIV.ASM diff --git a/th02_op.asm b/th02_op.asm index c19baf3b..fc8d31c2 100644 --- a/th02_op.asm +++ b/th02_op.asm @@ -695,33 +695,7 @@ include libs/BorlandC/dosenv.asm include libs/BorlandC/dosgdriv.asm include libs/BorlandC/errormsg.asm include libs/BorlandC/exit.asm - -; =============== S U B R O U T I N E ======================================= - -; Attributes: library function - -LXMUL@ proc far - push si - xchg ax, si - xchg ax, dx - test ax, ax - jz short loc_366B - mul bx - -loc_366B: - jcxz short loc_3672 - xchg ax, cx - mul si - add ax, cx - -loc_3672: - xchg ax, si - mul bx - add dx, si - pop si - retf -LXMUL@ endp - +include libs/BorlandC/f_lxmul.asm include libs/BorlandC/f_scopy.asm include libs/BorlandC/getvect.asm include libs/BorlandC/H_LDIV.ASM