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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [lib/] [mpy32s.S] - Blame information for rev 116

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

Line No. Rev Author Line
1 59 dgisselq
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;
3
; Filename:     mpy32s.S
4
;
5
; Project:      Zip CPU -- a small, lightweight, RISC CPU soft core
6
;
7
; Purpose:      Zip assembly file for running a 32-bit by 32-bit signed
8
;               multiply.  It works by adjusting the sign of the 32x32-bit
9
;               unsigned multiply.
10
;
11
; Creator:      Dan Gisselquist, Ph.D.
12 69 dgisselq
;               Gisselquist Technology, LLC
13 59 dgisselq
;
14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;
16
; Copyright (C) 2015, Gisselquist Technology, LLC
17
;
18
; This program is free software (firmware): you can redistribute it and/or
19
; modify it under the terms of  the GNU General Public License as published
20
; by the Free Software Foundation, either version 3 of the License, or (at
21
; your option) any later version.
22
;
23
; This program is distributed in the hope that it will be useful, but WITHOUT
24
; ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
; for more details.
27
;
28
; License:      GPL, v3, as defined and found on www.gnu.org,
29
;               http://www.gnu.org/licenses/gpl.html
30
;
31
;
32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33
;
34
;
35
;
36 45 dgisselq
; We could build mul32s (32-bit signed multiply) as
37 59 dgisselq
;
38
;       R0 - incoming value to be multiplied
39
;       R1 - Second multiplicand
40
;       R2 - Comes in as scratch
41
;       R3 - used as scratch internally
42 45 dgisselq
mpy32s:
43 59 dgisselq
        ADD     2,SP
44 69 dgisselq
        STO     R2,(SP)
45 59 dgisselq
        STO     R3,2(SP)
46
        ;
47
        CLR     R3              ; Keep track of resulting sign in R2
48 69 dgisselq
        TST     -1,R0           ; Is R0 negative?
49
        XOR.LT  1,R3            ; If so, resulting sign will be negative, and
50 45 dgisselq
        NEG.NZ  R0              ; then we negate R0 (R0 = ABS(R0))
51 69 dgisselq
        TST     -1,R1           ; Is R1 negative?
52
        XOR.LT  1,R3            ; If so, result will be opposite sign of before
53 45 dgisselq
        NEG.LT  R1              ; Now we get R1=ABS(R1)
54 59 dgisselq
 
55
        ; JSR mpy32u
56 69 dgisselq
        MOV     __HERE__+2(PC),R2       ; Do our unsigned multiply
57 59 dgisselq
        BRA     mpy32u
58
        ;
59 69 dgisselq
        TST     -1,R3           ; Check resulting sign
60 45 dgisselq
        BZ      ret_mul32s      ; If positive, do nothing more
61
        NOT     R0              ; If negative, negate the result
62
        NOT     R1
63
        ADD     $1,R1
64
        ADD.C   $1,R0
65
ret_mul32s:
66 69 dgisselq
        LOD     (SP),R2
67 59 dgisselq
        LOD     2(SP),R3
68
        ADD     2,SP
69
        JMP     R2
70 45 dgisselq
 

powered by: WebSVN 2.1.0

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