aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/avr8/words/mstar.asm
blob: a25d4a1f9d3ff90bb6ae3d56f841f182f8009b48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
; ( n1 n2 -- d) 
; Arithmetics
; multiply 2 cells to a double cell
VE_MSTAR:
    .dw $ff02
    .db "m*"
    .dw VE_HEAD
    .set VE_HEAD = VE_MSTAR
XT_MSTAR:
    .dw PFA_MSTAR
PFA_MSTAR:
    movw temp0, tosl
    loadtos
    movw temp2, tosl
    ; high cell ah*bh
    muls temp3, temp1
    movw temp4, r0
    ; low cell  al*bl
    mul  temp2, temp0
    movw tosl, r0
    ; signed ah*bl
    mulsu temp3, temp0
    sbc   temp5, zeroh
    add   tosh,  r0
    adc   temp4, r1
    adc   temp5, zeroh
    
    ; signed al*bh
    mulsu temp1, temp2
    sbc   temp5, zeroh
    add   tosh,  r0
    adc   temp4, r1
    adc   temp5, zeroh

    savetos
    movw tosl, temp4
    jmp_ DO_NEXT