
REVERSE A LIST
Write a program to test your subroutine to reverse the order of a short list (less than 255 elements). The
list has length LISTLEN. The index register X points to the first element of the original list. Do the
reversal in place. That is, swap the first and last elements, the second and next-to-last elements, etc. Use
subroutines to make the program easier to debug.
**************************************
* TEST PROGRAM FOR
* 'REVERSE A LIST' SUBROUTINE
* INPUT: A LIST OF LENGTH 'LISTLEN'
* POINTED TO BY IX-REGISTER
* OUTPUT: A LIST IN REVERSE ORDER
* REGISTERS USED: X
* AUTHORS:
* DATE: / /
**************************************
* EQUATES
OUTSTRG EQU $FFC7
ORG $6000
* PROGRAM SECTION
MAIN LDS #$004A
LDX #LIST
JSR OUTSTRG
LDX #LIST
BSR REVERSE
LDX #LIST
JSR OUTSTRG
SWI
* MAIN DATA SECTION
LIST FCC "0123456789abcde"
LENGTH EQU *-LIST-1
FCB 4
LISTLEN FCB LENGTH
**************************************
* SUBROUTINE REVERSE
* REVERSES A LIST IN PLACE
* INPUT PARAMETERS:
* LIST LENGTH = 'LISTLEN'
* X POINTS TO 'LIST
* OUTPUT: REVERSED LIST
* SAVES AND RESTORES A,B,X,Y
**************************************
REVERSE EQU *
PSHA
PSHB
PSHX
PSHY
*
* PUT YOUR SUBROUTINE BODY HERE
*
* RESTORE REGISTERS
DONE PULY
PULX
PULB
PULA
* RETURN
RTS
* SUBROUTINE DATA SECTION
SWAP_NO RMB 1
SAVEX RMB 2