OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [lib/] [divs.S] - Blame information for rev 56

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 45 dgisselq
;
2
;       DIVS
3
;
4
;       Given R0,R1, computer R0 = R0/R1 and R1 = R0%R1 for signed R0,R1.
5
;       We'll call R0 (input) x, R1(input) y, result is such that
6
;       R0 * y + R1 = x.  Now let's work through our signs with an example
7
;       where x = +/- 22, and y = +/- 4:
8
;
9
;       x y
10
;       + +     No change, just call divu
11
;       - +     (x=-22,y= 4,R0=-5,R1=-2)
12
;       + -     (x= 22,y=-4,R0=-5,R1= 2)
13
;       - -     (x=-22,y=-4,R0= 5,R1=-2)
14
;
15
;
16
;
17
divs:   ; Given R0,R1, computer R0 = R0/R1 and R1 = R0%R1 for signed R0,R1
18
        SUB     2,SP
19
        ; (stall)
20
        STO     R3,2(SP)
21
        ;
22
        CLR     R3              ; Keep track of resulting sign in R2
23
        TST     -1,R0           ; Is R0 negative?
24
        MOV     ret_div32s(PC),R2
25
        LLO.LT  3,R3            ; If so, resulting sign will be negative, and
26
        NEG.LT  R0              ; then we negate R0 (R0 = ABS(R0))
27
        MOV.LT  divu_divs_return(PC),R2
28
        TST     -1,R1           ; Is R1 negative?
29
        XOR.LT  1,R3            ; If so, result will be opposite sign of before
30
        NEG.LT  R1              ; Now we get R1=ABS(R1)
31
        MOV.LT  divu_divs_return(PC),R2
32
        STO     R2,1(SP)
33
        BRA     divu            ; Do our unsigned multiply
34
        ; JSR   divu            ; Do our unsigned multiply
35
divu_divs_return:
36
        TST     1,R3            ; Check resulting sign
37
        NEG.NE  R0              ; Need to flip the sign of our result
38
        TST     2,R3            ; Now, if R1 was originally negative
39
        NEG.NE  R1              ; Then negate R1
40
ret_div32s:
41
        LOD     2(SP),R3
42
        ADD     2,SP
43
        RETN
44
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.