aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/msp430/words/um-slash-mod.asm
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-08-19 12:15:28 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-08-19 12:15:28 +0200
commit67d25d837ac55f28a366c0a3b262e439a6e75fc3 (patch)
treedf7715c7724c5935ab87c807f3b8b4ef529315e3 /amforth-6.5/msp430/words/um-slash-mod.asm
parente0d6784e89dba33226c0edb815bb974486fa7c48 (diff)
Add AmForth
Diffstat (limited to 'amforth-6.5/msp430/words/um-slash-mod.asm')
-rw-r--r--amforth-6.5/msp430/words/um-slash-mod.asm31
1 files changed, 31 insertions, 0 deletions
diff --git a/amforth-6.5/msp430/words/um-slash-mod.asm b/amforth-6.5/msp430/words/um-slash-mod.asm
new file mode 100644
index 0000000..3904e8d
--- /dev/null
+++ b/amforth-6.5/msp430/words/um-slash-mod.asm
@@ -0,0 +1,31 @@
+;C UM/MOD ud u1 -- u2 u3 unsigned 32/16->16
+ CODEHEADER(XT_UMSLASHMOD,6,"um/mod")
+ ; IROP1 = TOS register
+ MOV @PSP+,IROP2M ; get ud hi
+ MOV @PSP,IROP2L ; get ud lo, leave room on stack
+;
+; T.I. UNSIGNED DIVISION SUBROUTINE 32-BIT BY 16-BIT
+; IROP2M|IROP2L : IROP1 -> IRACL REMAINDER IN IROP2M
+; RETURN: CARRY = 0: OK CARRY = 1: QUOTIENT > 16 BITS
+DIVIDE: CLR IRACL ; CLEAR RESULT
+ MOV #17,IRBT ; INITIALIZE LOOP COUNTER
+DIV1: CMP IROP1,IROP2M ;
+ JLO DIV2
+ SUB IROP1,IROP2M
+DIV2: RLC IRACL
+ JC DIV4 ; Error: result > 16 bits
+ DEC IRBT ; Decrement loop counter
+ JZ DIV3 ; Is 0: terminate w/o error
+ RLA IROP2L
+ RLC IROP2M
+ JNC DIV1
+ SUB IROP1,IROP2M
+ SETC
+ JMP DIV2
+DIV3: CLRC ; No error, C = 0
+DIV4: ; Error indication in C
+; END T.I. ROUTINE Section 5.1.5 of MSP430 Family Application Reports
+ MOV IROP2M,0(PSP) ; remainder on stack
+ MOV IRACL,TOS ; quotient in TOS
+ NEXT
+