Division
ZXNet echo conference «real.speccy»
From Konstantin Samoylov → To All 4 July 1999
Tell me how to quickly submit a 2-byte number to 7?
Sincerely, SP/PoS.
From Renat Mamedov → To All 5 July 1999
July 04, 1999, Konstantin Samoylov writes to All:
KS> Tell me how to quickly submit a 2-byte number to 7?
I remember Nasreddin’s advice (to build a high mosque you need to turn
a deep well inside out).
The technology was in some of the latest formats...
Sincerely,
Renat
From Konstantin Samoylov → To All 6 July 1999
RM> I remember Nasreddin’s advice (to build a high mosque you need
RM> to turn a deep well inside out).
RM> The technology was in one of the latest formats...
Found it, only there was no division of 2-byte numbers. ;)
I had to do it by analogy. Here, maybe someone will need it. Input number in HL,
in B - divisor, result in DE.
ld hl,500
ld b,7
call div ; hl/b=de
....
div xor a
ld de,1
d1 sla l
rl h
rla
cp b
jr c,zer
sub b
sli e
rl d
jr nc,d1
ret
zer sla e
rl d
jr nc,d1
ret
Sincerely, SP/PoS.
From Vladimir Galtscev → To All 8 July 1999
Once upon a time, 06-07-99, crooked Moscow time at 17:54:54
Konstantin Samoylov, angrily kicking the keyboard, tried to convey
to Renat Mamedov about Division...
KS> Found it, only there was no division of 2-byte numbers. ;)
KS> I had to do it by analogy. Here, maybe someone will need it. The input number in
KS> HL,
KS> in B is a divisor, the result is in DE.
[yum prog]
Well, what the hell is this?
I always use the following. procedure:
ld bc,600
ld de,100
div ld a,b
ld b,#10
ld hl,0
div1 rl c
rla
adc hl,hl
sbc hl,de
jr nc,div2
add hl,de
div2 ccf
djnz div1
rl c
rla
ld b,a
ret
in BC at the input dividend
in DE at the input divisor
in BC at the output answer
in HL at the output remainder
like this.... ;)))))
See you later, Konstantin....
I was with you HORRIBLE -=STS=- of VSp...
From Viktor Kuzmin → To All 11 July 1999
KS> HL, in B - divisor, result in DE.
KS> ld hl,500
KS> ld b,7
KS> call div ; hl/b=de
KS> ....
KS> div xor a
KS> ld de,1
KS> d1 sla l
KS> rl h
KS> rla
KS> cp b
KS> jr c,zer
KS> sub b
KS> sli e
KS> rl d
KS> jr nc,d1
KS> ret
KS> zer sla e
KS> rl d
KS> jr nc,d1
KS> ret
I use a slightly different version (I somehow thought about this without a computer)
By changing the procedure that calls cool, you can divide any number of bits into 16
bits.
xx bits / 16 bits (without sign)
bc / de = bc
div:
ld hl,0
ld a,b
call cool
ld b,a
ld a,c
call cool
ld c,a
ret
cool:
add a,a
dup 8
adc hl,hl
sbc hl,de
jr nc,$+3
add hl,de
ccf
adc a,a
edup
ret
See ya later, KVA of E-mage ... [ZX] [Scorpion]
{ 2:451/19 / 500:152/1 / k...@softhome.net }
From Konstantin Samoylov → To All 12 July 1999
KS>> Input number in HL,
VG> Hy and what the hell is this?
It’s not a big deal, it’s a procedure for dividing a 2-byte number by a single-byte one.
VG> I always use the following. procedure:
Let's make some comparison of your procedure with the procedure I wrote based on the procedure from the ZX-FORMAT N7 magazine.
ld bc,600 ld hl,600
ld de,100 ld b,20
bars bytes clock bytes
div ld a,b 4 1 xor a 4 1
ld b,#10 7 2 ld de,#0001 10 3
ld hl,0 10 3 div1 add hl,hl 15 1
div1 rl c 8 2 rla 4 1
rla 4 1 cp b 4 1
adc hl,hl 15 2 jr c,div2 7/12 2
sbc hl,de 15 2 sub b 4 1
jr nc,div2 7/12 2 sli e 8 2
add hl,de 15 1 rl d 8 2
div2 ccf 4 1 jr nc,div1 7/12 2
djnz div1 8/13 2 ret 4 1
rl c 8 2 div2 sla e 8 2
rla 4 1 rl d 8 2
ld b,a 4 1 jr nc,div1 7/12 2
ret 4 1 ret 4 1
max - 1336 cycles max - 1021 cycles
min - 1172 cycles min - 1005 cycles
len - 24 bytes len - 24 bytes
>It looks like I calculated everything correctly, if you made a mistake somewhere, then don’t be offended, correct it.
BC at the input dividend hl - dividend
DE at the input divisor b - divisor
BC at the output answer de - answer
HL at the output remainder a - remainder
VG> like this.... ;)))))
Not like this, but like this! As can be seen from the above information on the timing and
comparison of the 2 procedures, your procedure noticeably lags behind and has greater
inconsistency in clock cycles than the procedure given by me. Here, of course, you can
object that you are dividing a 2-byte number by a 2-byte number, but initially I
asked for a quick procedure for dividing a 2-byte number by 7, so you lost in this round. ;) Full blast. ;)))) But no offense, okay?
My time will come, someone will write better than this, if they haven’t already. ;)
Sincerely, SP/PoS.
From Kirill Frolov → To All 14 July 1999
12 Jul 99 22:38, Konstantin Samoylov wrote to Vladimir Galtscev:
KS> ret 4 1 ret 4 1
For 4 cycles nothing works ON THE BUS (except for reading the COP). 2 bytes from the stack
it will take 10 cycles to pull out.
Kirill Frolov. [ZX]
From Vladimir Galtscev → To All 14 July 1999
KS> Let's make some comparison of your procedure with the procedure written by
KS> by me on
KS> based on the procedure from the ZX-FORMAT N7 magazine. ;)))))
KS> Not like that, but like this! As can be seen from the above information on timing
KS> and comparison
KS> of 2 procedures - your procedure is noticeably behind and has greater
KS> inconstancy across
KS> clock cycles than the procedure given by me. Here, of course, you can argue
KS> that y
KS> you are dividing a 2-byte number by a 2-byte number, but initially I asked
KS> a fast
KS> procedure for dividing a 2-byte number by 7, so you are in this round
KS> lost.
Oops, sorry. I somehow missed that speed is important...
And the procedure is not mine - it’s from Peter Cook’s toys...
KS> ;) Full blast. ;)))) Just no offense, okay?
Fig! I'm offended to the point of tears.... ;)))))))))
KS> My time will come, someone will write better than this, if they haven't already.
KS> ;)
Wrote, wrote....
:))
If the volume of the procedure is not important to you, then use division through
logarithms!!!!!!
This is the same kuuuuuuuullllll!!!!!!
By the way, you can multiply through logarithms, and raise to a power
and calculate the root....
Here.
If you want, I can teach.....
:))))
The procedure will take about 300-400 cycles....
Whenany operations.
And not 1000...
;))))))))
It works for me in DUKE_3D. There is both division and root.
From Yuri Nazarenko → To All 15 July 1999
KF> For 4 cycles, nothing works on the BUS (except for reading the COP). It will take 10 clock cycles to pull out 2 bytes from the
KF> stack.
Yes, the ret command is executed in 10 clock cycles, but when comparing two
programs for speed, this is not important because one has a brake and the other
the same.
All the best to you, Kirill!
Yuri Nazarenko/Rezidnet/Discovery group
e-mail : Yuri_Nazar...@zxnet.spb.ru
From Konstantin Samoylov → To All 16 July 1999
KF> It will take 10 clock cycles to pull out from the stack.
Ops, this is what it means to not sit at a computer for six months. :(
Sincerely, SP/PoS.
From Konstantin Samoylov → To All 16 July 1999
KS>> wrote. ;)
VG> Wrote, wrote....
VG> :))
VG> If the volume of the procedure is not important to you, then use division through
VG> logarithms!!!!!!
VG> This is kuyyyyyllllllll!!!!!!!
VG> By the way, through logarithms you can multiply, and raise to a power,
VG> and calculate the root....
VG> Here.
VG> If you want, I can teach you.....
VG> :))))
VG> The procedure will take about 300-400 cycles....
VG> For any operations.
Come on, show me, you will need to compare the ratio of speed to volume... :)
With respect, SP/PoS.
From Yuri Voynalovich → To All 17 July 1999
╞╣ayya, Vladimir!
│
├┤it was a hot summer day in the yard (Thu 15 Jul 1999, 00:49:00), but Vladimir
Galtscev tried to talk with Konstantin Samoylov about Division
VG> If the volume of the procedure is for you is not important, then use division through
VG> logarithms!!!!!! This is kuuuuuuuuuullllll!!!!!!
VG> By the way, you can multiply and raise to a power using logarithms,
VG> and calculate the root.... Here. If you want, I can teach you..... :))))
VG> The procedure will take about 300-400 cycles....
VG> For any operations.
So come on, learn quickly! ;))))
VG> It works for me in DUKE_3D. There is both a division and a root.
Oops! What kind of DUKE3D??? So you let it slip :))) Now you can’t just get away with it - throw in the demo version ;))
With best regards, Yuri Voynalovich.
[Powered by Z80] [intel outside] [AMMY] [ъ]
From Konstantin Samoylov → To All 18 July 1999
KF>> it will take 10 clock cycles to pull a byte from the stack.
YN> Yes, the ret command is executed in 10 clock cycles, but when comparing two
YN> programs for speed, this is not important because one has a brake and the other
YN> is the same.
So you suggest, suggest, and we’ll see.:)
With respect, SP/PoS.
From Vladimir Galtscev → To All 18 July 1999
[yum]
VG>> The procedure will take about 300-400 cycles....
VG>> For any operations.
KS> Come on, show me, you will need to compare the ratio of speed to volume... :)
The person probably hasn’t seen Spectrum Expert... It’s a pity. Everything is popularly described there about division through logarithms....
Okay.
Tablet for converting to log. takes up #300 bytes.
Tablet decruncher - something around 100-150.
If you’re really interested, I’ll throw everything here
(division, multiplication, root, power).
2(co)mod: is it possible? I have a very hard time with soap....
From Vladimir Galtscev → To All 19 July 1999
YV> Oops! What kind of DUKE3D??? So you let it slip :))) Now it’s not so easy
YV> you can’t get away with it
YV> - throw in the demo version ;))
Eh-uh...... Mmmmmmm.... a-a-o-o-oo....
Hmmmmm....
Hdaaaaaaa.....
uh... Kind of such a din 3d...
Well, okay, okay, I’ll tell you right now:
duke on the PC? convert from the original PC Duke.
That's it...
Banana in your ear, Yuri.... :)