Heaven/TQA #1 Posted December 28, 2004 stupid question but i need a solution for this... normally i would do a loop like this: ldx #100 loop lda tab,x sta destination,x dex bpl loop but what if x>=128? f.e. i need above routine for 160 bytes... my question seems little bit stupid but i want to avoid a inx, cpx... maybe bvs etc? any ideas? Quote Share this post Link to post Share on other sites
Heaven/TQA #2 Posted December 28, 2004 oh... i forgot to mention... of course it should perform the x=0 as well... Quote Share this post Link to post Share on other sites
vdub_bobby #3 Posted December 29, 2004 oh... i forgot to mention... of course it should perform the x=0 as well... Well, this is ugly, but I think it will work... ldx #100 Loop lda tab,X sta destination,X txa beq Done dex bne Loop beq Loop Done Heh. Quote Share this post Link to post Share on other sites
Paul Slocum #4 Posted December 29, 2004 I'd say just use BNE and add an extra STA destination,x after the loop. Only uses 3 extra bytes and no extra cycles. Although I always just use BNE and STA destination-1,x. I can't think of many situations where that won't work except maybe where you have some tricky page alignment issues. -paul Quote Share this post Link to post Share on other sites
Paul Slocum #5 Posted December 29, 2004 correction, LDA/STA after the loop. 6 extra bytes (or less if zero page) Still not a significant cost unless you have a ton of these (which I'm guessing is not the case). Quote Share this post Link to post Share on other sites
Thomas Jentzsch #6 Posted December 29, 2004 ldx #160 .loop : lda tab-1,x sta destination-1,x dex bne .loop Quote Share this post Link to post Share on other sites
Heaven/TQA #7 Posted December 29, 2004 thanks guys... thomas... i came up with one of yours suggestions in meantime... sometimes small things seems more complicated than they are... thanks... (btw.... it's for boinxx and it's screenwrapper scroll routine...) Quote Share this post Link to post Share on other sites
carlsson #8 Posted December 30, 2004 Here's an extra ugly variant, if you want to avoid offset-1 : lda #159; will be 160 bytes including index #0 loop: tax lda src,x sta dest,x txa sec sbc #$01 bcs loop done: No, I'm not really serious that this is a good alternative. The CPX solution is two bytes shorter (and the offset-1 BNE is four bytes shorter). And that is without counting all the cycles wasted in each turn of the loop. Quote Share this post Link to post Share on other sites