Implement lldiv and imaxdiv functions.

These do 64-bit division and return a struct with the quotient and remainder.
This commit is contained in:
Stephen Heumann 2021-02-05 18:11:37 -06:00
parent d1d0358e4b
commit b072f5d042
2 changed files with 138 additions and 0 deletions

View File

@ -534,6 +534,40 @@ lb1 lla addr,div_t return the result
div_t ds 8
end
****************************************************************
*
* lldiv_t lldiv(long long n, long long d)
*
* Inputs:
* n - numerator
* d - denominator
*
* Outputs:
* lldiv_t - contains result & remainder
*
****************************************************************
*
lldiv start
imaxdiv entry
addr equ 1
csubroutine (8:n,8:d),4
phb use local addressing
phk
plb
ph8 n do the divide
ph8 d
jsl ~CDIV8
pl8 lldiv_t
pl8 lldiv_t+8
lla addr,lldiv_t return the result
plb
creturn 4:addr
lldiv_t ds 16
end
****************************************************************
*
* void qsort(base, count, size, compar)

View File

@ -585,3 +585,107 @@
DC I4'&DCB'
~RESTM
MEND
macro
&l ph8 &n1
lclc &c
&l anop
&c amid &n1,1,1
aif s:longa=1,.a
rep #%00100000
.a
aif "&c"="#",.d
aif "&c"="[",.b
aif "&c"<>"{",.c
&c amid &n1,l:&n1,1
aif "&c"<>"}",.g
&n1 amid &n1,2,l:&n1-2
&n1 setc (&n1)
.b
ldy #6
~&SYSCNT lda &n1,y
pha
dey
dey
bpl ~&SYSCNT
ago .e
.c
ldx #6
~&SYSCNT lda &n1,x
pha
dex
dex
bpl ~&SYSCNT
ago .e
.d
&n1 amid &n1,2,l:&n1-1
bra ~b&SYSCNT
~a&SYSCNT dc i8"&n1"
~b&SYSCNT ldx #6
~c&SYSCNT lda ~a&SYSCNT,x
pha
dex
dex
bpl ~c&SYSCNT
.e
aif s:longa=1,.f
sep #%00100000
.f
mexit
.g
mnote "Missing closing '}'",16
mend
macro
&l pl8 &n1
lclc &c
&l anop
aif s:longa=1,.a
rep #%00100000
.a
&c amid &n1,1,1
aif "&c"<>"{",.b
&c amid &n1,l:&n1,1
aif "&c"<>"}",.f
&n1 amid &n1,2,l:&n1-2
pla
sta (&n1)
ldy #2
pla
sta (&n1),y
ldy #4
pla
sta (&n1),y
ldy #6
pla
sta (&n1),y
ago .d
.b
aif "&c"<>"[",.c
pla
sta &n1
ldy #2
pla
sta &n1,y
ldy #4
pla
sta &n1,y
ldy #6
pla
sta &n1,y
ago .d
.c
pla
sta &n1
pla
sta &n1+2
pla
sta &n1+4
pla
sta &n1+6
.d
aif s:longa=1,.e
sep #%00100000
.e
mexit
.f
mnote "Missing closing '}'",16
mend