| 1 |
59 |
dgisselq |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
| 2 |
|
|
;
|
| 3 |
|
|
; Filename: mpyu.S
|
| 4 |
|
|
;
|
| 5 |
|
|
; Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
| 6 |
|
|
;
|
| 7 |
|
|
; Purpose: Zip assembly file for running doing an unsigned 32x32 bit
|
| 8 |
|
|
; multiply..
|
| 9 |
|
|
;
|
| 10 |
|
|
; Creator: Dan Gisselquist, Ph.D.
|
| 11 |
|
|
; Gisselquist Tecnology, LLC
|
| 12 |
|
|
;
|
| 13 |
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
| 14 |
|
|
;
|
| 15 |
|
|
; Copyright (C) 2015, Gisselquist Technology, LLC
|
| 16 |
|
|
;
|
| 17 |
|
|
; This program is free software (firmware): you can redistribute it and/or
|
| 18 |
|
|
; modify it under the terms of the GNU General Public License as published
|
| 19 |
|
|
; by the Free Software Foundation, either version 3 of the License, or (at
|
| 20 |
|
|
; your option) any later version.
|
| 21 |
|
|
;
|
| 22 |
|
|
; This program is distributed in the hope that it will be useful, but WITHOUT
|
| 23 |
|
|
; ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 24 |
|
|
; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 25 |
|
|
; for more details.
|
| 26 |
|
|
;
|
| 27 |
|
|
; License: GPL, v3, as defined and found on www.gnu.org,
|
| 28 |
|
|
; http://www.gnu.org/licenses/gpl.html
|
| 29 |
|
|
;
|
| 30 |
|
|
;
|
| 31 |
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
| 32 |
|
|
;
|
| 33 |
|
|
;
|
| 34 |
|
|
;
|
| 35 |
|
|
mpy32u: ; unsigned R0 * unsigned R1 -> unsigned R0:R1, R2 = rtn addr (on stack)
|
| 36 |
|
|
SUB 2,SP
|
| 37 |
|
|
STO R3,1(SP)
|
| 38 |
|
|
STO R4,2(SP)
|
| 39 |
45 |
dgisselq |
MOV R0,R2
|
| 40 |
|
|
MULU R1,R2 ; R2 = Low order bits, low(R0) * low(R1)
|
| 41 |
|
|
MOV R0,R3
|
| 42 |
|
|
LSR 16,R3 ; Put high order bits in lower half of R3
|
| 43 |
|
|
MULU R1,R3 ; R3 = Mid order bits, high(R0) * low(R1)
|
| 44 |
|
|
LSR 16,R1 ; R1 = High order bits of R1, being done w/ low order
|
| 45 |
|
|
MOV R1,R4 ;
|
| 46 |
|
|
MUL R0,R4 ; R4 = Mid order bits, low(R0) * high(R1)
|
| 47 |
|
|
LSR 16,R0
|
| 48 |
|
|
MULU R1,R0 ; R0 = High order bits, high(R0) * high(R1)
|
| 49 |
|
|
ADD R3,R4 ; R4 = sum of mid order bits
|
| 50 |
|
|
ADD.C 0x010000,R0 ; Add in the carry (if it happened)
|
| 51 |
|
|
MOV R4,R3
|
| 52 |
|
|
LSR 16,R3
|
| 53 |
|
|
ADD R3,R0 ; R0 = high order bits plus high order mid-bits
|
| 54 |
|
|
LSL 16,R4
|
| 55 |
|
|
ADD R4,R2 ; R2 = low order bits plus low order mid-bits
|
| 56 |
|
|
ADD.C 1,R0 ; Add in the carry to R0 (if it happened)
|
| 57 |
|
|
MOV R2,R1 ; Place low order bits into R1
|
| 58 |
59 |
dgisselq |
;
|
| 59 |
|
|
LOD 1(SP),R3
|
| 60 |
|
|
LOD 2(SP),R4
|
| 61 |
|
|
LOD 3(SP),R2
|
| 62 |
|
|
ADD 2,SP
|
| 63 |
|
|
JMP R2
|