Lda Ldx Ldy Sta Stx Sty

addressing modes; LDX and LDY each have five addressing modes; while STX and STY have three, and STA has seven. Recall that addressing modes determine how the CPU locates data that is retrieved from memory or how it locates where data is to be stored. The large number of addressing modes provided by the 6502 processor is an advantage in machine language programming because it allows the programmer more options in writing code for a given task.

In Boxes 18, 19, and 20 the STA, STX, and STY instructions use absolute addressing. The LDA, LDX, and LDY instructions use either the immediate mode of addressing or absolute addressing. These two addressing modes are used a great deal in machine language programs and will rapidly become very familiar to you. On the other hand, they both suffer from a severe limitation. Neither of these modes is useful for retrieving data from, or storing data in, an array or table.

Many of the tasks carried out by machine language routines involve either moving blocks of data called strings or arrays, or manipulation of data stored in a table. Since these are very common programming jobs, they are one of the first things that a beginning assembly language programmer should master. Both arrays and tables are stored in contiguous memory locations. Very often what is required is to move a block of data from one location to another or to access the items in a table in sequential order. Since the 6502 is an 8 bit processor, these manipulations occur one byte at a time. As a consequence, the program structure usually is a loop that cycles as many times as there elements in the array.

The DLI routine in Box 21 illustrates the basic elements needed to repeatedly loop through a table. In the program, six display list interrupts are written into a Graphics 2 display list. At each interrupt, the routine loads a color number from a table of values and puts it into the background color register. In order to do this properly, the program needs a way to keep track of its position in the color table and needs to determine when it has reached the end of the color table. The first task is handled by using a pointer and indexed addressing. The second by a compare and branch sequence.

BOX 21 Display List Interrupt Color Table

1 REM »* DLI COLOR TABLE EXAMPLE *» 5 REM * SET UP COLOR TABLE *

10 FOR CT=0 TO 5 20 READ D:P0K'E 1568+CT.D 30 NEXT CT

50 POKE 1336+31,31:REM INITIALIZE COUNTERS

60 REM » PUT SIX INTERRUPTS INTO THE DISPLAY LIST *

70 GRAPHICS 18

80 DL=PEEK(560)+PEEK(561)»256

100 POKE DL+C,135:NEXT C

180 REM « SET UP DLI SERVICE ROUTINE *

190 FOR J=0 TO 30:READ B:POKE 1536+J,B:NEXT J

200 DATA 72,138,72,238,31,6,174, 31,6,189,0,6,141,10,:

210 DATA 141,26,208,224,37,208,5,169.

31,141,31,6,104,170,104,64

220 POKE 512,0:POKE 513,6

2 30 POKE 54286,192 240 GOTO 240

BOX 21. Display List Interrupt Color Table

The service routine, pointer, and color table have been loaded into page six as follows:

■ 31 bytes of machine language routine at locations 1536 through 1566.

■ The pointer at location 1567.

■ 6 bytes of the color table at 1568 through 1573.

The service routine may be split into sections as follows:

Section I: Save registers to stack and increment the pointer.

0 0

Post a comment

  • Receive news updates via email from this site