math_code segment code
rseg math_code
fact_table: db 0xab, 0xaa, 0xaa, 0x2a ;1/3! = 1/6
db 0x22, 0x22, 0x22, 0x02 ;1/5! = 1/120
db 0xd0, 0x00, 0x0d, 0x00 ;1/7! = 1/5040
db 0x3c, 0x2e, 0x00, 0x00 ;1/9! = 1/362880
db 0x6c, 0x00, 0x00, 0x00 ;1/11! = 1/39916800 ;(pi/4)^11/11! = 0x00000008
db 0x00, 0x00, 0x00, 0x00
pi4: db 0x69, 0x21, 0xa2, 0xda, 0x0f, 0xc9 ;pi/4 = 3.141592653589793.../4
pi2: db 0xd2, 0x42, 0x44, 0xb5, 0x1f, 0x92 ;pi/2 = 3.141592653589793.../2, 最高字节为0x01, 不参加运算
.
.
.
.
mul_1632: ;r0r1 X mult[0~3] --> r2~r7; ;101 bytes; <= 108t
;未验证, 冒然使用后果自负!
;破坏 Acc, B, F0, PSW
mov a, mult ;a0 X b0
mov b, r0
mul ab
mov r2, a
mov r3, b
mov a, mult + 2 ;a2 X b0
mov b, r0
mul ab
mov r4, a
mov r5, b
mov a, mult + 3 ;a3 X b1 ;a0b0, a2b0, a3b1 --> r2~r7
mov b, r1
mul ab
mov r6, a
mov r7, b
mov a, mult ;a0 X b1
mov b, r1
mul ab
add a, r3
mov r3, a
mov a, b
addc a, r4
mov r4, a
mov f0, c
mov a, mult + 2 ;a2 X b1
mov b, r1
mul ab
mov c, f0
addc a, r5
mov r5, a
mov a, b
addc a, r6
mov r6, a
jnc $ + 3
inc r7 ;a0b0, a0b1, a2b0, a2b1, a3b1
mov a, mult + 1 ;a1 X b0
mov b, r0
mul ab
add a, r3
mov r3, a
mov a, b
addc a, r4
mov r4, a
mov f0, c
mov a, mult + 3 ;a3 X b0
mov b, r0
mul ab
mov c, f0
addc a, r5
mov r5, a
mov a, b
addc a, r6
mov r6, a
jnc $ + 3
inc r7 ;a0b0, a0b1, a1b0, a2b0, a2b1, a3b0, a3b1
mov a, mult + 1 ;a1 X b1 ;a0b0, a0b1, a1b0, a1b1, a2b0, a2b1, a3b0, a3b1
mov b, r1
mul ab
add a, r4
mov r4, a
mov a, b
mul_160:addc a, r5
mov r5, a
jnc $ + 7
inc r6
mov a, r6
jnz $ + 3
inc r7
ret
mul_32: ;mul[t0~3] X mult[4~7] --> r0~7; ;46 bytes, <= 267T
;不需要验证了吧 :-P
;破坏 [mult(4~9)], Acc, B, F0, PSW
mov r0, mult + 4
mov r1, mult + 5
lcall mul_1632
mov r0, mult + 6
mov r1, mult + 7
mov mult + 4, r2
mov mult + 5, r3
mov mult + 6, r4
mov mult + 7, r5
mov mult + 8, r6
mov mult + 9, r7
lcall mul_1632
mov r0, mult + 4
mov r1, mult + 5
mov a, mult + 6
add a, r2
mov r2, a
mov a, mult + 7
addc a, r3
mov r3, a
mov a, mult + 8
addc a, r4
mov r4, a
mov a, mult + 9
sjmp mul_160 |