Initial commit of files related to NED architecture.
[ned1] / software / assembly_fragments / multiply.asm
CommitLineData
bc5b63cf
AT
1# Operands
2WORD_174
3WORD_186
4
5# Multiplication routine
6# Restrictions:
7# Positive numbers only (31 shifts max since operands are twos-complement)
8# No overflow checking
9
10multiply
11 WORD_2147483648 # For use in setting sign for left shifts.
12 IM_0 # For magnitude of left/right shifts.
13 LDSP+0 # Sets up stack location to build/store result.
14 #-----
15testbit #
16 LDSP+3 #
17 LDSP+2 #
18 SHIFT # Check Nth bit of second operand.
19 IM_1 #
20 AND #
21 TEST #
22 #-----
23 BRZ>skipadd #
24 LDSP+4 #
25 LDSP+3 #
26 LDSP+3 #
27 OR # Shift and add first operand to result if indicated.
28 SHIFT #
29 ADD #
30skipadd #
31 #-----
32 LDSP+1 #
33 IM_1 # Increment counter for shift magnitude
34 ADD #
35 STSP+1 #
36 #-----
37 IM_30 #
38 NOT #
39 IM_1 #
40 ADD # Test for completion of multiplication subroutine (31 shifts).
41 LDSP+2 #
42 ADD #
43 TEST #
44 BRZ>cleanup # If finished, cleanup and return from subroutine with result on TOS.
45 #-----
46 IM_0 #
47 TEST # If not finished, repeat this process on the next bit.
48 BRZ>testbit #
49 #-----
50cleanup #
51 STSP+0 #
52 STSP+0 #
53 STSP+0 # Remove all subroutine temporaries from stack and return result on TOS.
54 STSP+0 #
55 HALT #