|
;Function `demo` **************************************** |
|
;void demo() |
|
;{ |
|
; int row; |
|
; int col; |
|
; char grid[64]; |
|
; int index; |
|
; for(index=0; index<64; index++) |
|
; { |
|
; grid[index] = 'a'+index; |
|
; } |
|
; for(row=0; row<8; row++) |
|
; printf("\n"); |
|
; for(col=0; col<8; col++) |
|
; showoff(row, col, grid); |
|
; |
|
; return; |
|
;} |
|
|
|
;Important constants |
|
gridsize:.EQUATE 64 ;Size of the grid |
|
roocsize:.EQUATE 8 ;Size of a row/column |
|
|
|
;callee/local variable info |
|
row: .EQUATE 0 ;local variable #2d |
|
col: .EQUATE 2 ;local variable #2d |
|
grid: .EQUATE 4 ;local 8x8 array #1c64a |
|
index: .EQUATE 68 ;local variable #2d |
|
dframe: .EQUATE 70 ;size of local frame |
|
0004 24 demo: NOP0 |
|
0005 680046 SUBSP dframe,i ;allocate #index #grid #col #row |
|
;(index=0; |
|
0008 C00000 LDA 0,i |
|
000B E30044 STA index,s ; |
|
|
|
000E 24 dfors: NOP0 ;Demo FOR loop Start |
|
;index<64 |
|
000F C30044 LDA index,s |
|
0012 B00040 CPA gridsize,i |
|
0015 0E0030 BRGE dfore |
|
|
|
;grid[index] = 'a'+index; |
|
;;Prepare to access [index] for a char-sized array |
|
0018 CB0044 LDX index,s |
|
|
|
;;Get right-hand value into accumulator |
|
001B C00061 LDA 'a',i |
|
001E 730044 ADDA index,s |
|
|
|
;;Perform assignment |
|
0021 F60004 STBYTEA grid,sx ;;Byte Array stored entirely on local stack: SX mode |
|
|
|
;index++) |
|
0024 C30044 LDA index,s |
|
0027 700001 ADDA 1,i |
|
002A E30044 STA index,s |
|
002D 04000E BR dfors |
|
0030 24 dfore: NOP0 ;Demo FOR loop End |
|
|
|
|
|
; for(row=0; row<8; row++) |
|
0031 C00000 LDA 0,i |
|
0034 E30000 STA row,s |
|
0037 24 rloops: NOP0 |
|
0038 C30000 LDA row,s |
|
003B B00008 CPA roocsize,i |
|
003E 0E0089 BRGE rloope |
|
; printf("\n"); |
|
0041 50000A CHARO '\n',i |
|
|
|
; for(col=0; col<8; col++) |
|
0044 C00000 LDA 0,i |
|
0047 E30002 STA col,s |
|
004A 24 cloops: NOP0 |
|
004B C30002 LDA col,s |
|
004E B00008 CPA roocsize,i |
|
0051 0E007C BRGE cloope |
|
|
|
; showoff(row, col, grid); |
|
; Tricky bit: C doesn't store arrays globally OR locally. |
|
; It just has a global or local POINTER to the array. |
|
; Functions inputting arrays expect a pointer, so we need to find &grid and pass THAT... |
|
0054 02 MOVSPA ;;A now has SP (pointer to row) |
|
0055 700004 ADDA grid,i ;;A now has SP+grid (pointer to grid) |
|
0058 E3FFFE STA GRINPUT,s ;;Preparing argument for function call |
|
005B C30000 LDA row,s |
|
005E E3FFFA STA ROWINPUT,s ;;Preparing argument for funcall |
|
0061 C30002 LDA col,s |
|
0064 E3FFFC STA COLINPUT,s ;;Preparing arg for funcall |
|
0067 680006 SUBSP XFRAME,i ;;Allocate #grinput #colinput #rowinput |
|
006A 16008E CALL showoff ; call function |
|
006D 600006 ADDSP XFRAME,i ;;Deallocate #rowinput #colinput #grinput |
|
|
|
|
|
;end row loop |
|
0070 C30002 LDA col,s |
|
0073 700001 ADDA 1,i |
|
0076 E30002 STA col,s |
|
0079 04004A BR cloops |
|
007C 24 cloope: NOP0 |
|
|
|
|
|
;end row loop |
|
007D C30000 LDA row,s |
|
0080 700001 ADDA 1,i |
|
0083 E30000 STA row,s |
|
0086 040037 BR rloops |
|
0089 24 rloope: NOP0 |
|
|
|
|
|
; return; |
|
;} |
|
008A 680046 SUBSP dframe,i ;deallocate #row #col #grid #index |
|
008D 58 RET0 |