Docsity

Reverse a List: Assembly Program for Reversing a Short List In-Place, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
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

Partial preview of the text

Download Reverse a List: Assembly Program for Reversing a Short List In-Place and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

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 $FFC

ORG $

* 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- 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