SOURCE VIEWER

mul_u32_u32.inc

Original bytes preserved. This is a browser-readable view.

DOWNLOAD ORIGINAL ↓

; CLARITAS TIP u32/1 - mul_u32_u32.inc
; Public: UMUL32

;
; ROM-independent transplant of OM-52C C-ROM routine EA49.
;
; Historical contract:
;   unsigned 32-bit multiplication
;   $15-$18 <- $15-$18 * $5-$8
;
; Library contract:
;   input:
;       $15-$18  unsigned 32-bit multiplicand, low word first
;       $5-$8    unsigned 32-bit multiplier,   low word first
;
;   output:
;       $15-$18  low 32 bits of the unsigned product
;
;   arithmetic:
;       product = (multiplicand * multiplier) mod 2^32
;
;   clobbers:
;       $0-$3
;       $10-$11
;       $5-$8      (historical loop shifts multiplier down to zero)
;
;   no overflow/status result is returned.
;
; C3 donor identity:
;   OM-52C historical bytes EA49..EA74
;   length 44 bytes
;   SHA-256:
;   6f3fbd594444131385a12c5645f0e6ae3dd850fa8315d1bd44f4be5110d39769
;
; This core deliberately preserves the historical destructive behavior.
; A non-destructive API, if later useful, belongs in a separate wrapper.

#LIST

UMUL32:
        LDM     $0,$15,4
        SBW     $15,$15
        SBW     $17,$17

_M32_LOOP:
        SBW     $10,$10
        SBCW    $5,$10
        JR      NZ,_M32_BIT
        SBCW    $7,$10
        RTN     Z

_M32_BIT:
        ANC     $5,$SY
        JR      Z,_M32_SHIFT
        ADW     $15,$SZ
        JR      NC,_M32_ADDHI
        ADW     $17,$SY

_M32_ADDHI:
        ADW     $17,$2

_M32_SHIFT:
        BIUW    $0
        ROUW    $2
        BIDW    $8
        RODW    $6
        JR      _M32_LOOP