Problem from Axor #1

ZXNet echo conference «code.zx»

From Vlad Sotnikov To All 15 September 2003

Hello, All! There is a byte X, in it you need to swap places, for example, the 2nd and 0th bits. My option is this: LD B,A BIT 0.A JR NZ,bit RES 0.B JR$+4 bit SET 0,B BIT 2,A JR NZ,bit2 RES 2,B JR$+4 bit2 SET 2,B LD A,B How can you make it shorter and faster? Vega/ex-Style Group. FIDO: 2:5030/1512 ZXNET: 500:812/19 E-mail: vega56@mail.ru

From Kirill Frolov To Vlad Sotnikov 15 September 2003

Press RESET immediately, Vlad Sotnikov! On Sun, 14 Sep 03 23:13:18 +0400, Vlad Sotnikov wrote: VS> There is a byte X, in it you need to swap places, for example, the 2nd and 0th bits. VS> My option is this: VS> LD B,A VS> BIT 0,A VS> JR NZ,bit VS> RES 0,B VS> JR $+4 VS> bit SET 0,B VS> BIT 2,A VS> JR NZ,bit2 VS> RES 2,B VS> JR $+4 VS> bit2 SET 2,B VS> LD A,B VS> How can you make it shorter and faster? If it’s much faster, then like this: ld h, "lookup table" / 256 ld l, a ld a, (hl) Otherwise, through logical operations (AND, OR, XOR), it will be a little faster than in your version by minimizing the number of conditional transitions.

From Evgeny Goljakov To Vlad Sotnikov 19 September 2003

Hello Vlad. Mon 15 Sep 02 Vlad Sotnikov -> All: VS> There is a byte X, it needs to be swapped, for example, the 2nd and VS> 0th bit. VS> How can you make it shorter and faster? how much shorter should you make it? Haven't you calculated how much is your option yet, or should we do it? Thank you for your attention.

From Aleksey Malov To Vlad Sotnikov 27 September 2003

Hi, Vlad! Monday September 15 2003 at 00:13 Vlad Sotnikov wrote to All about Problem from Axora #1 VS> Hello, All! VS> There is a byte X, in it you need to swap places, for example, the 2nd and 0th bits. VS> My option is this: VS> LD B,A VS> BIT 0,A VS> JR NZ,bit VS> RES 0,B VS> JR $+4 VS> bit SET 0,B VS> BIT 2,A VS> JR NZ,bit2 VS> RES 2,B VS> JR $+4 VS> bit2 SET 2,B VS> LD A,B tmin = 64 tmax = 78 size = 23 VS> How can you make it shorter and faster? ================== rrca ld b,a rrca ldc,a rrca ld d,a rl b rla rl c rla rl d rla time=60 size=15 ===================== ldc,a and 7 add a, tab ld l,a adc a,tab/256 subl ld h,a ld a,c and #f8 or(hl) tab db 0, 4, 2, 6, 1, 5, 3, 7 time=55 size=21 ================================ Well, that's the first thing that came to mind. In general, I forget the Spectrum assembler has become... Bye, Vlad! Vivid/Brainwave Team http://www.bwteam.org ICQ: 164514413

From Aleksey Malov To Aleksey Malov 27 September 2003

Hi, Aleksey! Saturday September 27 2003 at 00:08 Aleksey Malov wrote to Vlad Sotnikov about Задачка от Axor'a #1 AM> ================== AM> rrca AM> ld b,a AM> rrca AM> ld c,a AM> rrca AM> ld d,a AM> rl b AM> rla AM> rl c AM> rla AM> rl d AM> rla AM> time=60 AM> size=15 AM> ===================== Блин. Торможу... ld b,a rrca rrca rrca ld c,a rr b rla rlca rl c rla time = 48 size = 12 AM> Hу, это первое, что в голову пришло. А вообще, я забывать AM> спектрумовский ассемблер стал... Вот именно. Склероз Bye, Aleksey! Vivid / Brainwave Team http://www.bwteam.org ICQ: 164514413

From Evgeny Goljakov To Aleksey Malov 29 September 2003

Hello Aleksey. Sat 27 Sep 02 Aleksey Malov -> Aleksey Malov: AM> time = 48 AM> size = 12 Our Diamodns school represented by Merlin would offer: ;==#Exchange any 2 bits ;c 2003 Merlin/ZX Diamond ; in: a ;out: a AND 5 ;(%00000101) JP PE,W XOR 5 ;(%00000101) W... time 24 size 7 Unlike shifts, it can change any 2 bits without changes in code volume. And if you need not to change the remaining bits of A: ;#Exchange any 2 bits only ;c 2003 Merlin/ZX Diamond LD C,A AND 5 LD A,C JP PE,W XOR 5 W... time 32 size 9 AM>> Well, this is the first thing that came to mind. In general, I and the first thing I received was a summons to the military committee.. AM>> Spectrum assembler began to be forgotten... Merlin amazed me, he thought for 10 seconds. on the task It’s not for nothing that we chose his e-reader for Nicron ;))) Thank you for your attention.

From Ivan Roshin To Vlad Sotnikov 3 October 2003

Hello, Vlad! 15 Sep 2003 you wrote: VS> There is a byte X, it needs to be swapped, for example, the 2nd and VS> 0th bit. VS> My option is this: VS> LD B,A VS> BIT 0,A VS> JR NZ,bit VS> RES 0,B VS> JR $+4 VS> bit SET 0,B VS> BIT 2,A VS> JR NZ,bit2 VS> RES 2,B VS> JR $+4 VS> bit2 SET 2,B VS> LD A,B VS> How can you make it shorter and faster? Alex Xor asked me this too, I offered him this option: If both bits are equal, then nothing needs to be changed. If not are equal, then we change their values to the opposite ones using one XOR. LD B,A LD C,%00000101 ;The units in the mask correspond to ;bits exchanged. AND C JR Z,M1 ;Jump if both bits are 0. CP C JR NZ,M2 ;Jump if bits are not equal. M1 LD C,0 ;Bits are equal - reset the mask. M2 LD A,B XOR C Best regards, Ivan Roshchin.

From Aleksey Malov To Evgeny Goljakov 4 October 2003

*** Answer from area CARBON Hi, Evgeny! Monday September 29 2003 at 03:55 Evgeny Goljakov wrote to Aleksey Malov about Problem from Axor #1 EG> Unlike shifts, it can change any 2 bits without EG> changes in code volume. EG> And if you need not to change the remaining bits of A: EG> ;#Exchange any 2 bits only EG> ;c 2003 Merlin/ZX Diamond EG>LD C,A EG> AND 5 EG>LD A,C EG> JP PE,W EG>XOR 5 EG> W ... Cool!!! I have never been friends (in the sense, I have never used it in my programs) with the flag evenness... But it would be necessary... AM>>> Spectrum assembler began to be forgotten... EG> Merlin amazed me, he thought for 10 seconds. on the task EG> It’s not for nothing that we chose his e-reader for Nicron ;))) Yes, there are still coders in Spectrum villages... Bye, Evgeny! Vivid/Brainwave Team http://www.bwteam.org ICQ: 164514413