Re: A new article about 6502
Posted: Wed Sep 16, 2020 3:17 pm
Sorry, Ed. I accept partial responsibility for squirting the lighter fluid. I had a clear opportunity to move my post to my "efficient sign extension" thread and missed it.
Code: Select all
ldy #0
ldx #4
lda #hi(tab)
sta loop+2
tya
loop eor loop,y
iny
bne loop
inc loop+2
dex
bne loop
align 256
tab .byte <data> ;1000 bytes are here
Code: Select all
ldy #0
ldx #4
lda #hi(tab)
sta loop+2
tya
loop eor loop,y
iny
bne loop
inc loop+2
dex
bne loop
align 256
tab .byte <data> ;1000 bytes are here
Code: Select all
ldy #0
ldx #4
lda #hi(tab)
sta loop+2
tya
loop eor loop,y
iny
bne loop
inc loop+2
dex
bne loop
align 256
tab .byte <data> ;1000 bytes are here
Code: Select all
0200 00001 org $200
00002
0200 A0 00 [2] 00003 ldy #0
0202 A2 04 [2] 00004 ldx #4
0204 A9 03 [2] 00005 lda #>tab
0206 8D 020C [4] 00006 sta loop+2
0209 98 [2] 00007 tya
020A 59 0300 [4/5] 00008 loop eor tab,y ; BUG! Was loop,y
020D C8 [2] 00009 iny
020E D0 FA (020A) [2/3] 00010 bne loop
00011
0210 EE 020C [6] 00012 inc loop+2
0213 CA [2] 00013 dex
0214 D0 F4 (020A) [2/3] 00014 bne loop
00015
0300 00016 org $300
00017
0300 00018 tab
00019
00020 end
9267 cycles
22 bytes
Code: Select all
0100 00001 org $100
00002
0100 CE 0300 [3] 00003 ldx #Tab
0103 4F [2] 00004 clra
00005
0104 00006 Loop
0104 A8 00 [5] 00007 eora ,X
0106 08 [4] 00008 inx
00009
0107 8C 0700 [3] 00010 cpx #Tab+1024
010A 26 F8 (0104) [4] 00011 bne Loop
00012
0300 00013 org $300
00014
0300 00015 Tab
00016
00017 end
16389 cycles
12 bytes
Code: Select all
00031 ; W0 := S0 + S1 + S2;
00032
00033 ; ; 0 := v W0 -> 1
00034 ; ; 1 L r 2
00035
00036 ; ; 2 L v S0 -> 3
00037 ; ; 3 + v S1 -> 4
00038 ; ; 4 + v S2
00039
00040
00041 ; 1 L r 2
00042 ; 2 L v S0 -> 3
00043 ; 3 + v S1 -> 4
0029 18 [2] 00044 clc
002A A0 00 [2] 00045 ldy #0
002C A5 15 [3] 00046 lda S0
002E 10 01 (0031) [2/3] 00047 bpl 2f
0030 88 [2] 00048 dey
0031 00049 2:
0031 65 16 [3] 00050 adc S1
0033 AA [2] 00051 tax
0034 24 16 [3] 00052 bit S1
0036 10 01 (0039) [2/3] 00053 bpl 2f
0038 88 [2] 00054 dey
0039 00055 2:
0039 98 [2] 00056 tya
003A 69 00 [2] 00057 adc #0
00058 ; 4 + v S2
003C 18 [2] 00059 clc
003D A8 [2] 00060 tay
003E 8A [2] 00061 txa
003F 65 17 [3] 00062 adc S2
0041 AA [2] 00063 tax
0042 24 17 [3] 00064 bit S2
0044 10 01 (0047) [2/3] 00065 bpl 2f
0046 88 [2] 00066 dey
0047 00067 2:
0047 98 [2] 00068 tya
0048 69 00 [2] 00069 adc #0
00070 ; 0 := v W0 -> 1
004A 86 0D [3] 00071 stx W0
004C 85 0E [3] 00072 sta W0+1
Code: Select all
00031 * W0 := S0 + S1 + S2;
00032
00033 * * 0 := v W0 -> 1
00034 * * 1 L r 2
00035
00036 * * 2 L v S0 -> 3
00037 * * 3 + v S1 -> 4
00038 * * 4 + v S2
00039
00040
00041 * 1 L r 2
00042 * 2 L v S0 -> 3
00043 * 3 + v S1 -> 4
0029 D6 15 [3] 00044 ldab S0
002B 86 7F [2] 00045 ldaa #$7F ; Thanks Mike B!
002D 11 [2] 00046 cba
002E 82 7F [2] 00047 sbca #$7F
0030 7D 0016 [6] 00048 tst S1
0033 2A 01 (0036) [4] 00049 bpl 2f
0035 4A [2] 00050 deca
0036 00051 2:
0036 DB 16 [3] 00052 addb S1
0038 89 00 [2] 00053 adca #0
00054 * 4 + v S2
003A 7D 0017 [6] 00055 tst S2
003D 2A 01 (0040) [4] 00056 bpl 2f
003F 4A [2] 00057 deca
0040 00058 2:
0040 DB 17 [3] 00059 addb S2
0042 89 00 [2] 00060 adca #0
00061 * 0 := v W0 -> 1
0044 97 0D [4] 00062 staa W0
0046 D7 0E [4] 00063 stab W0+1
Code: Select all
remember current line for error reporting
obtain for loop state record
initialize in state record
load initial value into loop variable
goto loop body
loop top:
step loop variable
compare with end value
if end condition satisfied:
drop state record
go to loop exit
else:
store new loop variable value
go to loop body
loop body:
<do arbitrary stuff>
verify loop variable
goto loop top
loop exit:
Code: Select all
00293 ; 100 for I = 1 to 10 : next I
0B0C 00294 L00100:
00295 ifdef __TRACE
00296 ldx #<100
00297 lda #>100
00298 jsr Trace
00299 endif
00300 ifdef __ATLIN
0B0C A2 0C [2] 00301 ldx #<L00100
0B0E 8E 0F48 [4] 00302 stx ResLn_
0B11 A9 0B [2] 00303 lda #>L00100
0B13 8D 0F49 [4] 00304 sta ResLn_+1
00305 endif
00306
0B16 20 0C9D [6] 00307 jsr ForEnter
00308
0B19 A0 04 [2] 00309 ldy #4
0B1B A9 35 [2] 00310 lda #<T00000
0B1D 91 1E [6] 00311 sta (Ptr0),Y
0B1F C8 [2] 00312 iny
0B20 A9 0B [2] 00313 lda #>T00000
0B22 91 1E [6] 00314 sta (Ptr0),Y
00315
0B24 C8 [2] 00316 iny
0B25 A9 52 [2] 00317 lda #<I_
0B27 91 1E [6] 00318 sta (Ptr0),Y
0B29 C8 [2] 00319 iny
0B2A A9 0F [2] 00320 lda #>I_
0B2C 91 1E [6] 00321 sta (Ptr0),Y
00322
0B2E A2 01 [2] 00323 ldx #<1
0B30 A0 00 [2] 00324 ldy #>1
00325
0B32 4C 0B53 [3] 00326 jmp T00003
00327
0B35 00328 T00000:
0B35 A9 01 [2] 00329 lda #<1
0B37 18 [2] 00330 clc
0B38 6D 0F52 [4] 00331 adc I_
0B3B AA [2] 00332 tax
0B3C A9 00 [2] 00333 lda #>1
0B3E 6D 0F53 [4] 00334 adc I_+1
0B41 70 0B (0B4E) [2/3] 00335 bvs T00001
0B43 A8 [2] 00336 tay
00337
0B44 E0 0B [2] 00338 cpx #<11 ; Thanks Mike B!
0B46 E9 00 [2] 00339 sbc #>11
0B48 50 02 (0B4C) [2/3] 00340 bvc 2f
0B4A 49 80 [2] 00341 eor #$80
00342
0B4C 00343 2:
0B4C 30 03 (0B51) [2/3] 00344 bmi T00002
00345
0B4E 00346 T00001:
0B4E 4C 0CF0 [3] 00347 jmp ForExit
00348
0B51 00349 T00002:
0B51 68 [4] 00350 pla
0B52 68 [4] 00351 pla
00352
0B53 00353 T00003:
0B53 8E 0F52 [4] 00354 stx I_
0B56 8C 0F53 [4] 00355 sty I_+1
00356
0B59 A2 52 [2] 00357 ldx #<I_
0B5B A9 0F [2] 00358 lda #>I_
0B5D 20 0C5D [6] 00359 jsr ForNext
Code: Select all
. 00637 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
. 00638 ;
. 00639 ; For stack entry
. 00640 ;
. 00641 ; 0..1 - Next address
. 00642 ; 2..3 - Prev address
. 00643 ; 4..5 - Top of loop address
. 00644 ; 6..7 - Variable address
. 00645 ;
.0008 00646 FORSIZE equ 8
. 00647
. 00648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
. 00649 ;
. 00650 ; ForNext - Process NEXT statement
. 00651 ;
. 00652 ; Input:
. 00653 ; A:X = variable address
. 00654 ;
. 00655 ; Uses:
. 00656 ; Ptr0
. 00657 ;
.0C5D 00658 ForNext:
.0C5D A4 24 [3] 00659 ldy ForTop ; Point to current context
.0C5F 84 1E [3] 00660 sty Ptr0
.0C61 A4 25 [3] 00661 ldy ForTop+1
.0C63 84 1F [3] 00662 sty Ptr0+1
.0C65 D0 04 (0C6B) [2/3] 00663 bne ForN0
.0C67 A4 1E [3] 00664 ldy Ptr0
.0C69 F0 2D (0C98) [2/3] 00665 beq ForN2 ; Not currently within a FOR loop
. 00666
.0C6B 00667 ForN0:
.0C6B A0 07 [2] 00668 ldy #7
.0C6D D1 1E [5/6] 00669 cmp (Ptr0),Y ; Compare variable address
.0C6F D0 15 (0C86) [2/3] 00670 bne ForN1 ; Loop variable mismatch
.0C71 88 [2] 00671 dey
.0C72 8A [2] 00672 txa
.0C73 D1 1E [5/6] 00673 cmp (Ptr0),Y
.0C75 D0 0F (0C86) [2/3] 00674 bne ForN1
. 00675
.0C77 A0 04 [2] 00676 ldy #4
.0C79 B1 1E [5/6] 00677 lda (Ptr0),Y ; Jump to top of loop
.0C7B AA [2] 00678 tax
.0C7C C8 [2] 00679 iny
.0C7D B1 1E [5/6] 00680 lda (Ptr0),Y
.0C7F 86 1E [3] 00681 stx Ptr0
.0C81 85 1F [3] 00682 sta Ptr0+1
.0C83 6C 001E [5] 00683 jmp (Ptr0)
. 00684
.0C86 00685 ForN1
.0C86 A0 02 [2] 00686 ldy #2
.0C88 B1 1E [5/6] 00687 lda (Ptr0),Y ; Get previous context
.0C8A 85 24 [3] 00688 sta ForTop ; Save it
.0C8C AA [2] 00689 tax
.0C8D C8 [2] 00690 iny
.0C8E B1 1E [5/6] 00691 lda (Ptr0),Y
.0C90 85 25 [3] 00692 sta ForTop+1
.0C92 D0 D7 (0C6B) [2/3] 00693 bne ForN0 ; Retry if valid
.0C94 A4 24 [3] 00694 ldy ForTop
.0C96 D0 D3 (0C6B) [2/3] 00695 bne ForN0 ; Retry if valid
. 00696
.0C98 00697 ForN2
.0C98 A9 3E [2] 00698 lda #62 ; Report FOR-NEXT nesting error
.0C9A 4C 0D05 [3] 00699 jmp ErrH
. 00700
. 00701 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
. 00702 ;
. 00703 ; ForEnter - Create a new FOR loop context
. 00704 ;
. 00705 ; Input:
. 00706 ; ForTop = address of current context (0 if not in FOR loop)
. 00707 ; ForStack = bottom of context stack
. 00708 ;
. 00709 ; Output:
. 00710 ; Ptr0 = the address of the FOR stack entry
. 00711 ;
. 00712 ; Uses
. 00713 ; Ptr1
. 00714 ;
.0C9D 00715 ForEnter:
.0C9D A5 24 [3] 00716 lda ForTop
.0C9F 05 25 [3] 00717 ora ForTop+1
.0CA1 F0 18 (0CBB) [2/3] 00718 beq ForE0 ; Not currently within a FOR loop
. 00719
.0CA3 A6 24 [3] 00720 ldx ForTop ; Point to most recent entry
.0CA5 86 20 [3] 00721 stx Ptr1
.0CA7 A5 25 [3] 00722 lda ForTop+1
.0CA9 85 21 [3] 00723 sta Ptr1+1
. 00724
.0CAB A0 00 [2] 00725 ldy #0
.0CAD B1 20 [5/6] 00726 lda (Ptr1),Y ; Get next address
.0CAF AA [2] 00727 tax
.0CB0 C8 [2] 00728 iny
.0CB1 B1 20 [5/6] 00729 lda (Ptr1),Y
.0CB3 D0 0A (0CBF) [2/3] 00730 bne ForE1
.0CB5 E0 00 [2] 00731 cpx #0
.0CB7 F0 0F (0CC8) [2/3] 00732 beq ForE2 ; No next, go allocate it
.0CB9 D0 04 (0CBF) [2/3] 00733 bne ForE1
. 00734
.0CBB 00735 ForE0:
.0CBB A2 54 [2] 00736 ldx #<ForStack ; Start with the bottom of the stack
.0CBD A9 0F [2] 00737 lda #>ForStack
. 00738
.0CBF 00739 ForE1:
.0CBF 86 24 [3] 00740 stx ForTop ; It is now the current context
.0CC1 85 25 [3] 00741 sta ForTop+1
.0CC3 86 1E [3] 00742 stx Ptr0
.0CC5 85 1F [3] 00743 sta Ptr0+1
. 00744
.0CC7 60 [6] 00745 rts
. 00746
.0CC8 00747 ForE2:
.0CC8 A2 08 [2] 00748 ldx #FORSIZE ; Allocate a new entry
.0CCA A9 00 [2] 00749 lda #0
.0CCC 20 0E5B [6] 00750 jsr Alloc
. 00751
.0CCF A9 00 [2] 00752 lda #0
.0CD1 A8 [2] 00753 tay
.0CD2 91 1E [6] 00754 sta (Ptr0),Y ; Set next to nil
.0CD4 C8 [2] 00755 iny
.0CD5 91 1E [6] 00756 sta (Ptr0),Y
. 00757
.0CD7 A5 24 [3] 00758 lda ForTop ; Set prev pointer
.0CD9 C8 [2] 00759 iny
.0CDA 91 1E [6] 00760 sta (Ptr0),Y
.0CDC A5 25 [3] 00761 lda ForTop+1
.0CDE C8 [2] 00762 iny
.0CDF 91 1E [6] 00763 sta (Ptr0),Y
. 00764
.0CE1 A5 1E [3] 00765 lda Ptr0 ; Store address of allocation
.0CE3 A0 00 [2] 00766 ldy #0
.0CE5 91 20 [6] 00767 sta (Ptr1),Y
.0CE7 AA [2] 00768 tax
.0CE8 A5 1F [3] 00769 lda Ptr0+1
.0CEA C8 [2] 00770 iny
.0CEB 91 20 [6] 00771 sta (Ptr1),Y
. 00772
.0CED 4C 0CBF [3] 00773 jmp ForE1 ; Return it
. 00774
. 00775 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
. 00776 ;
. 00777 ; ForExit - Drop a FOR loop context
. 00778 ;
. 00779 ; Input:
. 00780 ; ForTop = current context
. 00781 ;
. 00782 ; Output:
. 00783 ; ForTop = the previous context
. 00784 ; X = the address of the context
. 00785 ;
.0CF0 00786 ForExit:
.0CF0 A6 24 [3] 00787 ldx ForTop ; Point to most recent entry
.0CF2 86 1E [3] 00788 stx Ptr0
.0CF4 A6 25 [3] 00789 ldx ForTop+1
.0CF6 86 1F [3] 00790 stx Ptr0+1
. 00791
.0CF8 A0 02 [2] 00792 ldy #2
.0CFA B1 1E [5/6] 00793 lda (Ptr0),Y ; Point to previous entry
.0CFC AA [2] 00794 tax
.0CFD C8 [2] 00795 iny
.0CFE B1 1E [5/6] 00796 lda (Ptr0),Y
. 00797
.0D00 86 24 [3] 00798 stx ForTop ; It is now the top
.0D02 85 25 [3] 00799 sta ForTop+1
. 00800
.0D04 60 [6] 00801 rts
Code: Select all
00117 * 100 for I = 1 to 10 : next I
0109 00118 L00100
00119 ifdef __TRACE
00120 ldx #100
00121 jsr Trace
00122 endif
00123 ifdef __ATLIN
0109 CE 0109 [3] 00124 ldx #L00100
010C FF 0426 [6] 00125 stx ResLn_
00126 endif
00127
010F BD 0231 [9] 00128 jsr ForEnter
00129
0112 86 01 [2] 00130 ldaa #T00000>>8
0114 A7 04 [6] 00131 staa 4,X
0116 86 28 [2] 00132 ldaa #T00000&$FF
0118 A7 05 [6] 00133 staa 5,X
00134
011A 86 04 [2] 00135 ldaa #I_>>8
011C A7 06 [6] 00136 staa 6,X
011E 86 30 [2] 00137 ldaa #I_&$FF
0120 A7 07 [6] 00138 staa 7,X
00139
0122 86 00 [2] 00140 ldaa #1>>8
0124 C6 01 [2] 00141 ldab #1&$FF
00142
0126 20 19 (0141) [4] 00143 bra T00003
00144
0128 00145 T00000
0128 86 00 [2] 00146 ldaa #1>>8
012A C6 01 [2] 00147 ldab #1&$FF
00148
012C FB 0431 [4] 00149 addb I_+1
012F B9 0430 [4] 00150 adca I_
00151
0132 81 00 [2] 00152 cmpa #10>>8
0134 22 06 (013C) [4] 00153 bhi T00001
0136 25 07 (013F) [4] 00154 blo T00002
0138 C1 0A [2] 00155 cmpb #10&$FF
013A 23 03 (013F) [4] 00156 bls T00002
00157
013C 00158 T00001
013C 7E 0269 [3] 00159 jmp ForExit
00160
013F 00161 T00002
013F 31 [4] 00162 ins
0140 31 [4] 00163 ins
00164
0141 00165 T00003
0141 B7 0430 [5] 00166 staa I_
0144 F7 0431 [5] 00167 stab I_+1
00168
00169
0147 86 04 [2] 00170 ldaa #I_>>8
0149 C6 30 [2] 00171 ldab #I_&$FF
014B BD 0216 [9] 00172 jsr ForNext
Code: Select all
. 00384 ******************************************************************************
. 00385 *
. 00386 * For stack entry
. 00387 *
. 00388 * 0..1 - Next address
. 00389 * 2..3 - Prev address
. 00390 * 4..5 - Top of loop address
. 00391 * 6..7 - Variable address
. 00392 *
.0008 00393 FORSIZE equ 8
. 00394
. 00395 ******************************************************************************
. 00396 *
. 00397 * ForNext - Process NEXT statement
. 00398 *
. 00399 * Input:
. 00400 * A:B = variable address
. 00401 *
.0216 00402 ForNext
.0216 DE 12 [4] 00403 ldx ForTop ; Point to current context
.0218 27 12 (022C) [4] 00404 beq ForN2 ; Not currently within a FOR loop
. 00405
.021A 00406 ForN0
.021A A1 06 [5] 00407 cmpa 6,X ; Compare variable address
.021C 26 08 (0226) [4] 00408 bne ForN1 ; Loop variable mismatch
.021E E1 07 [5] 00409 cmpb 7,X
.0220 26 04 (0226) [4] 00410 bne ForN1
. 00411
.0222 EE 04 [6] 00412 ldx 4,X ; Jump to top of loop
.0224 6E 00 [4] 00413 jmp ,X
. 00414
.0226 00415 ForN1
.0226 EE 02 [6] 00416 ldx 2,X ; Get previous context
.0228 DF 12 [5] 00417 stx ForTop ; Save it
.022A 26 EE (021A) [4] 00418 bne ForN0 ; Retry if valid
. 00419
.022C 00420 ForN2
.022C 86 3E [2] 00421 ldaa #62 ; Report FOR-NEXT nesting error
.022E 7E 0270 [3] 00422 jmp ErrH
. 00423
. 00424 ******************************************************************************
. 00425 *
. 00426 * ForEnter - Create a new FOR loop context
. 00427 *
. 00428 * Input:
. 00429 * ForTop = address of current context (0 if not in FOR loop)
. 00430 * ForStack = bottom of context stack
. 00431 *
. 00432 * Output:
. 00433 * X = the address of the FOR stack entry
. 00434 *
.0231 00435 ForEnter
.0231 DE 12 [4] 00436 ldx ForTop ; Point to most recent entry
.0233 27 0D (0242) [4] 00437 beq ForE1 ; Not currently within a FOR loop
. 00438
.0235 A6 00 [5] 00439 ldaa ,X ; Get next address
.0237 E6 01 [5] 00440 ldab 1,X
.0239 26 03 (023E) [4] 00441 bne ForE0
.023B 4D [2] 00442 tsta
.023C 27 0A (0248) [4] 00443 beq ForE3 ; No next, go allocate it
. 00444
.023E 00445 ForE0
.023E EE 00 [6] 00446 ldx ,X ; Use the next one
. 00447
.0240 20 03 (0245) [4] 00448 bra ForE2
. 00449
.0242 00450 ForE1
.0242 CE 0432 [3] 00451 ldx #ForStack ; Start with the bottom of the stack
. 00452
.0245 00453 ForE2
.0245 DF 12 [5] 00454 stx ForTop ; It is now the current context
. 00455
.0247 39 [5] 00456 rts
. 00457
.0248 00458 ForE3
.0248 CE 0008 [3] 00459 ldx #FORSIZE ; Allocate a new entry
.024B BD 0385 [9] 00460 jsr Alloc
. 00461
.024E 4F [2] 00462 clra
.024F A7 00 [6] 00463 staa ,X ; Set next to nil
.0251 A7 01 [6] 00464 staa 1,X
. 00465
.0253 96 12 [3] 00466 ldaa ForTop ; Set prev pointer
.0255 A7 02 [6] 00467 staa 2,X
.0257 96 13 [3] 00468 ldaa ForTop+1
.0259 A7 03 [6] 00469 staa 3,X
. 00470
.025B DE 12 [4] 00471 ldx ForTop ; Store address of allocation
.025D 96 0C [3] 00472 ldaa Ptr0
.025F A7 00 [6] 00473 staa ,X
.0261 96 0D [3] 00474 ldaa Ptr0+1
.0263 A7 01 [6] 00475 staa 1,X
. 00476
.0265 DE 0C [4] 00477 ldx Ptr0 ; Point to new entry
. 00478
.0267 20 DC (0245) [4] 00479 bra ForE2 ; Return it
. 00480
. 00481 ******************************************************************************
. 00482 *
. 00483 * ForExit - Drop a FOR loop context
. 00484 *
. 00485 * Input:
. 00486 * ForTop = current context
. 00487 *
. 00488 * Output:
. 00489 * ForTop = the previous context
. 00490 * X = the address of the context
. 00491 *
.0269 00492 ForExit
.0269 DE 12 [4] 00493 ldx ForTop ; Point to most recent entry
. 00494
.026B EE 02 [6] 00495 ldx 2,X ; Point to previous entry
. 00496
.026D DF 12 [5] 00497 stx ForTop ; It is now the top
. 00498
.026F 39 [5] 00499 rts
Code: Select all
12 remember current line for error reporting
37 obtain for loop state record
40 initialize in state record
15 load initial value into loop variable
goto loop body
loop top:
10x16 step loop variable
9x22 compare with end value
1x13
if end condition satisfied:
43 drop state record
go to loop exit
else:
9x8 store new loop variable value
go to loop body
loop body:
<do arbitrary stuff>
10x72 verify loop variable
goto loop top
loop exit:
Total = 1310 cycles
252 bytes
Code: Select all
9 remember current line for error reporting
30 obtain for loop state record
32 initialize in state record
18 load initial value into loop variable
goto loop body
loop top:
10x12 step loop variable
9x24 compare with end value
1x16
if end condition satisfied:
23 drop state record
go to loop exit
else:
9x10 store new loop variable value
go to loop body
loop body:
<do arbitrary stuff>
10x49 verify loop variable
goto loop top
loop exit:
Total = 1044 cycles
159 bytes
Code: Select all
ldy #0 ;2
ldx #4 ;2
lda #hi(tab) ;2
sta loop+2 ;3
tya ;2
loop eor loop,y ;4 I think this takes an extra cycle as page flip over so shuld add 1+1+1 (3) more, but ignore
iny ;2
bne loop ;2
inc loop+2 ;5
dex ;2
bne loop ;2
align 256
tab .byte <data> ;1000 bytes are here
Code: Select all
ldaa #0 ;2
ldx #1000 ;4
loop:
dex ;4
eora tab,X ;5
bne loop ;4
Code: Select all
ldaa #0 ;2
ldx #1000 ;4
loop:
dex ;4
eora tab,X ;5
bne loop ;4