From 67d25d837ac55f28a366c0a3b262e439a6e75fc3 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 19 Aug 2017 12:15:28 +0200 Subject: Add AmForth --- amforth-6.5/msp430/words/um-slash-mod.asm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 amforth-6.5/msp430/words/um-slash-mod.asm (limited to 'amforth-6.5/msp430/words/um-slash-mod.asm') 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 + -- cgit v1.2.3