goal: cycle through memory locations $2000 (8192)throug (8192+3600) compare the value of each of those locations: for i = 0 to 3600 byte=peek(8192+i) if byte=0 then out= 2 if byte>128 then out = 1 if byte<128 then out = 0 poke 11792+i,out nexti assembly first attempt: no errors! but does it work? seems not to work all of the time. better faster ways? Rich http://rich12345.tripod.com ORG $300 LDA #$00 STA LD+1 ;initialize load position LDA #$20 STA LD+2 LDA #$10 STA ST+1 ;initialize store position LDA #$2E STA ST+2 LD LDA $2000 BEQ ZERO CMP #128 BPL A128 BMI B128 ZERO LDA #2 JMP ST A128 LDA #1 JMP ST B128 LDA #0 JMP ST ST STA $2000 INC LD+1 ;INCREMENT LOAD INC ST+1 ; AND STORE BEQ NEXT ; IF WRAPPED AROUND TO 0, INCREMENT HI BYTE LDA LD+2 ;SEE IF HI BYTE IS GOOD? CMP #$2E BNE A1 LDA LD+1 CMP #10 ;SEE IF LOW BYTE IS GOOD? BEQ RTS ;YES, DONE BEQ NEXT A1 JMP LD ;DO NEXT BYTEBYTE RTS RTS ;RETURN NEXT INC LD+2 INC ST+2 JMP LD aiiadict@hotmail.com (Rich) wrote: >goal: > >cycle through memory locations $2000 (8192)throug (8192+3600) >compare the value of each of those locations: > >for i = 0 to 3600 >byte=peek(8192+i) >if byte=0 then out= 2 >if byte>128 then out = 1 >if byte<128 then out = 0 > >poke 11792+i,out >nexti > > >assembly first attempt: no errors! > >but does it work? seems not to work all of the time. > >better faster ways? > >Rich >http://rich12345.tripod.com > > > > > >ORG $300 > > LDA #$00 > STA LD+1 ;initialize load position > LDA #$20 > STA LD+2 > > > LDA #$10 > STA ST+1 ;initialize store position > LDA #$2E > STA ST+2 > >LD LDA $2000 > BEQ ZERO > CMP #128 > BPL A128 > BMI B128 > >ZERO LDA #2 > JMP ST >A128 LDA #1 > JMP ST >B128 LDA #0 > JMP ST >ST STA $2000 > > > INC LD+1 ;INCREMENT LOAD > INC ST+1 ; AND STORE > BEQ NEXT ; IF WRAPPED AROUND TO 0, INCREMENT HI BYTE > > LDA LD+2 ;SEE IF HI BYTE IS GOOD? > CMP #$2E > BNE A1 > LDA LD+1 > CMP #10 ;SEE IF LOW BYTE IS GOOD? > BEQ RTS ;YES, DONE > BEQ NEXT >A1 JMP LD ;DO NEXT BYTEBYTE > >RTS RTS ;RETURN > >NEXT INC LD+2 > INC ST+2 > JMP LD The problem is that when you increment the low bytes of the addresses, you assume that both wrap to 0 at the same time, but one is initialized to 0 and the other to $10. If you don't _have_ to start the result array at $2E10, but could start it at $2F00 instead, then your code would work. Just to pick nits, your code actually sets the output to 1 if the input byte is greater than _or equal_ to 128. If this is intended, then the compare is unnecessary, since you can simply test the sign bit. Also, of course, the JMP ST just before ST is redundant. I assume that the BEQ NEXT is just a typo, since NEXT doesn't exist, and the following line A1 JMP LD seems to do the job. BTW, you could save a byte by using BNE LD. How about coding this address check as: LDA LD+2 ;See if high byte is good CMP #$2E BCC LD ; Keep looping if < $2E LDA LD+1 CMP #$10 (I think you want hex here) BCC LD ; Keep looping if < $10 RTS I assume that speed is not much of an issue, but if it is, then the increment of the low bytes of the addresses can be replaced by an increment of either X or Y. This would also solve the problem above of having different starting low bytes, since the index register would be the same for both operations. -michael Check out amazing quality sound for 8-bit Apples on my Home page: http://members.aol.com/MJMahon/ In article <20040509222658.12637.00001016@mb-m15.aol.com>, mjmahon@aol.com (Michael J. Mahon) wrote: > aiiadict@hotmail.com (Rich) wrote: > > >goal: > > > >cycle through memory locations $2000 (8192)throug (8192+3600) > >compare the value of each of those locations: > > > >for i = 0 to 3600 > >byte=peek(8192+i) > >if byte=0 then out= 2 > >if byte>128 then out = 1 > >if byte<128 then out = 0 > > > >poke 11792+i,out > >nexti [Rich's code and Michael's thoughtful analysis elided.] > -michael > > Check out amazing quality sound for 8-bit Apples on my > Home page: http://members.aol.com/MJMahon/ Like Michael, I interpreted your spec to mean "if byte>=128 then out = 1". It took me a while to see that you had written self-modifying code. I've been bitten by this once too often:-) Here's a version using the indirect indexed addressing mode: org $300 from equ $50 ; zero page to equ from+2 src equ $2000 len equ $0E10 dest equ src+len lda #>src ; lo byte sta from lda #dest ; lo byte sta to lda #len ; leftover byte count beq done dey bne test done rts John ---- jmatthews at wright dot edu www dot wright dot edu/~john.matthews/