Need help working something out.

Discussion about ZX80 / ZX81 Software
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Need help working something out.

Post by mrtinb »

I think this is even simpler using Z80's build-in CPI (Compare and increment).

Code: Select all

  10 REM 01111111101111111110
  20 REM [ASM]
     409C 011400        LD BC,0014 ;Length 20
     409F 3E1C          LD A,1C    ;Test for "0"
     40A1 218240        LD HL,4082 ;Adress 16514
     40A4 110000        LD DE,0000 ;Reset counter
     40A7 EDA1     LOOP CPI
     40A9 2001          JR NZ NOTF
     40AB 13            INC DE
     40AC EAA740   NOTF JP PE LOOP
     40AF D5            PUSH DE    ;Return counter
     40B0 C1            POP BC
     40B1 C9            RET
  30 PRINT USR 16540
Attachments
FIND0.p
(982 Bytes) Downloaded 150 times
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: Need help working something out.

Post by Moggy »

Thanks to you also Martin and Zsolt. :ugeek:

Not only do I have different ways to do this thanks to all you guys I am also learning how code like this works with different ways to achieve the result,so once again many thanks to you all. :D
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Need help working something out.

Post by XavSnap »

1 REM ; the 800 characters
10 LET C=-22400 ; the counter 800 * code "0"
20 FOR A=16514 TO 17313 ; the address loop (800 step)
30 LET C=C+PEEK A ; set counter
40 NEXT A
50 PRINT "1=";C,"0=";800-C ; the results
Hoops, sorry !
Nice code...
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply