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

Subversion Repositories zipcpu

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

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 69 dgisselq
lib_divs: ; Given R0,R1, computer R0 = R0/R1 and R1 = R0%R1 for signed R0,R1
18 45 dgisselq
        SUB     2,SP
19 69 dgisselq
        STO     R2,(SP)
20 45 dgisselq
        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 69 dgisselq
        BRA     lib_divu        ; Do our unsigned multiply
33 45 dgisselq
        ; JSR   divu            ; Do our unsigned multiply
34
divu_divs_return:
35
        TST     1,R3            ; Check resulting sign
36
        NEG.NE  R0              ; Need to flip the sign of our result
37
        TST     2,R3            ; Now, if R1 was originally negative
38
        NEG.NE  R1              ; Then negate R1
39
ret_div32s:
40 69 dgisselq
        LOD     (SP),R2
41 45 dgisselq
        LOD     2(SP),R3
42
        ADD     2,SP
43 59 dgisselq
        JMP     R2
44 45 dgisselq
 

powered by: WebSVN 2.1.0

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