URL
https://opencores.org/ocsvn/zipcpu/zipcpu/trunk
Subversion Repositories zipcpu
[/] [zipcpu/] [trunk/] [sw/] [lib/] [divu.S] - Rev 69
Compare with Previous | Blame | View Log
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Filename: divu.S;; Project: Zip CPU -- a small, lightweight, RISC CPU soft core;; Purpose: Zip assembly file for running doing an unsigned divide.; This routine is also called by the signed divide.;; Creator: Dan Gisselquist, Ph.D.; Gisselquist Technology, LLC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Copyright (C) 2015, Gisselquist Technology, LLC;; This program is free software (firmware): you can redistribute it and/or; modify it under the terms of the GNU General Public License as published; by the Free Software Foundation, either version 3 of the License, or (at; your option) any later version.;; This program is distributed in the hope that it will be useful, but WITHOUT; ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License; for more details.;; License: GPL, v3, as defined and found on www.gnu.org,; http://www.gnu.org/licenses/gpl.html;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;lib_divu: ; Given R0,R1, computer R0 = R0/R1 and R1 = R0%R1TST -1,R1; BNZ divu_valid_divideCLR.Z R0 ; Should be a divide by zero error / trapJMP.Z R2divu_valid_divide:SUB 2,SPSTO R2,(SP)STO R3,1(SP);LDI 1,R2 ; Here's where we record the bit we are working onCLR R3 ; Here's where we build our result; Our original loop rejoin point, before a touch of unrollingCMP R1,R0BRC divu_prep_next_bitTST -1,R1BLT divu_top_bit_setdivu_rotate_up_r1:LSL 1,R2LSL 1,R1/*CMP R1,R0BRC divu_prep_next_bitTST -1,R1BGT divu_rotate_up_r1*/BLT divu_top_bit_setCMP R1,R0BRC divu_prep_next_bit;LSL 1,R2LSL 1,R1BLT divu_top_bit_setCMP R1,R0BRC divu_prep_next_bit;LSL 1,R2LSL 1,R1BLT divu_top_bit_setCMP R1,R0BRC divu_prep_next_bit;LSL 1,R2LSL 1,R1BLT divu_top_bit_setCMP R1,R0BRC divu_prep_next_bitBRA divu_rotate_up_r1divu_top_bit_set:CMP R1,R0BRC divu_prep_next_bitSUB R1,R0OR R2,R3divu_prep_next_bit:LSR 1,R1LSR 1,R2BZ divu_record_result;divu_next_loop:CMP R1,R0 ;SUB.GE R1,R0 ; We also switch to signed arithmetic, sinceOR.GE R2,R3 ; after the first bit, we are signedLSR 1,R1LSR 1,R2BZ divu_record_result;CMP R1,R0SUB.GE R1,R0OR.GE R2,R3LSR 1,R1LSR 1,R2BZ divu_record_result;CMP R1,R0SUB.GE R1,R0OR.GE R2,R3LSR 1,R1LSR 1,R2BZ divu_record_result;CMP R1,R0SUB.GE R1,R0OR.GE R2,R3LSR 1,R1LSR 1,R2BNZ divu_next_loopdivu_record_result:MOV R0,R1MOV R3,R0LOD (SP),R2LOD 1(SP),R3ADD 2,SPJMP R2
