mirror of
https://github.com/irmen/prog8.git
synced 2024-12-26 14:29:35 +00:00
implemented almost all math operations
This commit is contained in:
parent
a77d3c92ad
commit
d97da3bb7b
@ -86,7 +86,8 @@ result .byte 0,0,0,0
|
|||||||
.pend
|
.pend
|
||||||
|
|
||||||
|
|
||||||
divmod_ub .proc
|
divmod_ub_asm .proc
|
||||||
|
; TODO divmod_ub_asm doesn't work correctly. (remainder = ok, quotient = FAULTY)
|
||||||
; -- divide A by Y, result quotient in Y, remainder in A (unsigned)
|
; -- divide A by Y, result quotient in Y, remainder in A (unsigned)
|
||||||
; division by zero will result in quotient = 255 and remainder = original number
|
; division by zero will result in quotient = 255 and remainder = original number
|
||||||
sty P8ZP_SCRATCH_REG
|
sty P8ZP_SCRATCH_REG
|
||||||
|
@ -339,7 +339,7 @@ idiv_b .proc
|
|||||||
eor #$ff
|
eor #$ff
|
||||||
sec
|
sec
|
||||||
adc #0 ; make num2 positive
|
adc #0 ; make num2 positive
|
||||||
+ jsr math.divmod_ub
|
+ jsr math.divmod_ub_asm
|
||||||
sta _remainder
|
sta _remainder
|
||||||
tya
|
tya
|
||||||
plp ; get sign of result
|
plp ; get sign of result
|
||||||
@ -357,7 +357,7 @@ idiv_ub .proc
|
|||||||
inx
|
inx
|
||||||
ldy P8ESTACK_LO,x
|
ldy P8ESTACK_LO,x
|
||||||
lda P8ESTACK_LO+1,x
|
lda P8ESTACK_LO+1,x
|
||||||
jsr math.divmod_ub
|
jsr math.divmod_ub_asm
|
||||||
tya
|
tya
|
||||||
sta P8ESTACK_LO+1,x
|
sta P8ESTACK_LO+1,x
|
||||||
rts
|
rts
|
||||||
@ -410,7 +410,7 @@ remainder_ub .proc
|
|||||||
inx
|
inx
|
||||||
ldy P8ESTACK_LO,x ; right operand
|
ldy P8ESTACK_LO,x ; right operand
|
||||||
lda P8ESTACK_LO+1,x ; left operand
|
lda P8ESTACK_LO+1,x ; left operand
|
||||||
jsr math.divmod_ub
|
jsr math.divmod_ub_asm
|
||||||
sta P8ESTACK_LO+1,x
|
sta P8ESTACK_LO+1,x
|
||||||
rts
|
rts
|
||||||
.pend
|
.pend
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
|||||||
%import c64textio
|
%import c64textio
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
; TODO implement DIV asm generation
|
; TODO implement signed byte/word DIV asm generation, fix unsigned DIV asm generation (for in-place)
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
@ -11,17 +11,17 @@ main {
|
|||||||
div_ubyte(100, 6, 16)
|
div_ubyte(100, 6, 16)
|
||||||
div_ubyte(255, 2, 127)
|
div_ubyte(255, 2, 127)
|
||||||
|
|
||||||
div_byte(0, 1, 0)
|
;div_byte(0, 1, 0) ; TODO implement
|
||||||
div_byte(100, -6, -16)
|
;div_byte(100, -6, -16) ; TODO implement
|
||||||
div_byte(127, -2, -63)
|
;div_byte(127, -2, -63) ; TODO implement
|
||||||
|
|
||||||
div_uword(0,1,0)
|
div_uword(0,1,0)
|
||||||
div_uword(40000,500,80)
|
div_uword(40000,500,80)
|
||||||
div_uword(43211,2,21605)
|
div_uword(43211,2,21605)
|
||||||
|
|
||||||
div_word(0,1,0)
|
;div_word(0,1,0) ; TODO implement
|
||||||
div_word(-20000,500,-40)
|
;div_word(-20000,500,-40) ; TODO implement
|
||||||
div_word(-2222,2,-1111)
|
;div_word(-2222,2,-1111) ; TODO implement
|
||||||
|
|
||||||
div_float(0,1,0)
|
div_float(0,1,0)
|
||||||
div_float(999.9,111.0,9.008108108108107)
|
div_float(999.9,111.0,9.008108108108107)
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
%import c64textio
|
%import c64textio
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
; TODO implement MUL asm generation
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
%import c64textio
|
%import c64textio
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
; TODO implement REMAINDER asmgeneration
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
%import c64flt
|
%import c64textio
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
float f1 = 2.2
|
ubyte b1 = 2
|
||||||
float f2 = 1.0
|
ubyte b2 = 13
|
||||||
float f4 = 4.0
|
ubyte b3 = 100
|
||||||
float f5 = 5.0
|
|
||||||
|
|
||||||
f1 /= f2+f4
|
uword w1 = 2222
|
||||||
c64flt.print_f(f1)
|
uword w2 = 11
|
||||||
|
uword w3 = 33
|
||||||
|
|
||||||
|
w1 %= (w2+w3)
|
||||||
|
txt.print_uw(w1)
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user