From 2bb5361c24ba03d0b7b0169616c2d19610a36802 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Thu, 4 Feb 2021 23:58:54 -0600 Subject: [PATCH] Add a new file for 64-bit integer routines, initially with an unsigned multiply. This file will be expanded with more support routines as needed. The unsigned multiply routine uses the core multiplication loop from the 64-bit signed multiply routine in SysLib, with new entry/exit code for the unsigned version. --- int64.asm | 92 ++++++++++++++++++++++++++++++++++++++ int64.macros | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++ make | 4 +- 3 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 int64.asm create mode 100644 int64.macros diff --git a/int64.asm b/int64.asm new file mode 100644 index 0000000..b166a66 --- /dev/null +++ b/int64.asm @@ -0,0 +1,92 @@ + keep obj/int64 + mcopy int64.macros + case on + +**************************************************************** +* +* Int64 - 64-bit integer math routines. +* +* This code implements routines called by ORCA/C generated +* code for operations on 64-bit integers. +* +**************************************************************** +* +Int64 start dummy segment + end + +**************************************************************** +* +* ~UMUL8 - Eight Byte Unsigned Integer Multiply +* +* Inputs: +* NUM1,NUM2 - operands +* +* Outputs: +* NUM2 - result +* +**************************************************************** +* +~UMUL8 START + +ANS EQU 3 +RETURN EQU ANS+16 +NUM1 EQU RETURN+3 +NUM2 EQU NUM1+8 + + LDA #0 set up initial working value + PHA + PHA + PHA + PHA + LDA 18,s initially, ANS = NUM1 + PHA + LDA 18,s + PHA + LDA 18,s + PHA + LDA 18,s + PHA + PHD + TSC + TCD +; +; Do a 64 bit by 64 bit multiply. +; + LDY #64 64 bit multiply +ML1 LDA ANS + LSR A + BCC ML2 + CLC add multiplicand to the partial product + LDA ANS+8 + ADC NUM2 + STA ANS+8 + LDA ANS+10 + ADC NUM2+2 + STA ANS+10 + LDA ANS+12 + ADC NUM2+4 + STA ANS+12 + LDA ANS+14 + ADC NUM2+6 + STA ANS+14 +ML2 ROR ANS+14 shift the interim result + ROR ANS+12 + ROR ANS+10 + ROR ANS+8 + ROR ANS+6 + ROR ANS+4 + ROR ANS+2 + ROR ANS + DEY loop until done + BNE ML1 + + move4 ANS,NUM2 move return value and address + move4 ANS+4,NUM2+4 + move4 RETURN-1,NUM1+4 + PLD fix stack, DP + TSC + CLC + ADC #24 + TCS + RTL + END diff --git a/int64.macros b/int64.macros new file mode 100644 index 0000000..aedead3 --- /dev/null +++ b/int64.macros @@ -0,0 +1,123 @@ + macro +&l move4 &m1,&m2 + lclb &yistwo +&l ~setm + ~lda &m1 + ~sta &m2 + ~lda.h &m1 + ~sta.h &m2 + ~restm + mend + macro +&l ~lda &op + lclc &c +&c amid "&op",1,1 + aif "&c"<>"{",.b +&c amid "&op",l:&op,1 + aif "&c"="}",.a + mnote "Missing closing '}'",2 +&op setc &op} +.a +&op amid "&op",2,l:&op-2 +&op setc (&op) +.b +&l lda &op + mend + macro +&l ~lda.h &op +&l anop + lclc &c +&c amid "&op",1,1 + aif "&c"="[",.b + aif "&c"<>"{",.d +&c amid "&op",l:&op,1 + aif "&c"="}",.a + mnote "Missing closing '}'",2 +&op setc &op} +.a +&op amid "&op",2,l:&op-2 +&op setc (&op) +.b + aif &yistwo,.c +&yistwo setb 1 + ldy #2 +.c +&op setc "&op,y" + lda &op + mexit +.d + aif "&c"<>"#",.e +&op amid "&op",2,l:&op-1 +&op setc "#^&op" + lda &op + mexit +.e + lda 2+&op + mend + macro +&l ~restm +&l anop + aif (&~la+&~li)=2,.i + sep #32*(.not.&~la)+16*(.not.&~li) + aif &~la,.h + longa off +.h + aif &~li,.i + longi off +.i + mend + macro +&l ~setm +&l anop + aif c:&~la,.b + gblb &~la + gblb &~li +.b +&~la setb s:longa +&~li setb s:longi + aif s:longa.and.s:longi,.a + rep #32*(.not.&~la)+16*(.not.&~li) + longa on + longi on +.a + mend + macro +&l ~sta &op + lclc &c +&c amid "&op",1,1 + aif "&c"<>"{",.b +&c amid "&op",l:&op,1 + aif "&c"="}",.a + mnote "Missing closing '}'",2 +&op setc &op} +.a +&op amid "&op",2,l:&op-2 +&op setc (&op) +.b +&l sta &op + mend + macro +&l ~sta.h &op +&l anop + lclc &c +&c amid "&op",1,1 + aif "&c"="[",.b + aif "&c"<>"{",.d +&c amid "&op",l:&op,1 + aif "&c"="}",.a + mnote "Missing closing '}'",2 +&op setc &op} +.a +&op amid "&op",2,l:&op-2 +&op setc (&op) +.b + aif &yistwo,.c +&yistwo setb 1 + ldy #2 +.c +&op setc "&op,y" + sta &op + mexit +.d + sta 2+&op + mend diff --git a/make b/make index a436612..1676424 100644 --- a/make +++ b/make @@ -19,7 +19,7 @@ if {#} == 0 unset exit end - for i in cc ctype string stdlib time setjmp orca fcntl vars toolglue signal + for i in cc ctype string stdlib time setjmp orca fcntl vars toolglue signal int64 Newer obj/{i}.a {i}.asm if {Status} != 0 set exit on @@ -39,7 +39,7 @@ echo delete orcalib delete orcalib set list vars.a assert.a cc.a setjmp.a ctype.a string.a stdlib.a -set list {list} time.a signal.a toolglue.a orca.a fcntl.a stdio.a +set list {list} time.a signal.a toolglue.a orca.a fcntl.a stdio.a int64.a for i in {list} echo makelib orcalib +obj/{i} makelib orcalib +obj/{i}