ack/mach/6500/libem/exg.s
1984-12-17 11:03:13 +00:00

34 lines
801 B
ArmAsm

.define Exg
! This subroutine exchanges two groups of bytes on the top of the
! stack. The groups may consist of atmost 255 bytes.
! This number is in register Y.
! The exchange is from ADDR, ADDR+1 to ADDR+2, ADDR+3
Exg:
lda SP+1
ldx SP+2
stx ADDR ! address of first group (lowbyte)
sta ADDR+1 ! address of first group (highbyte)
sty Ytmp ! save number of bytes to be exchanged
clc
lda SP+2
adc Ytmp
sta ADDR+2 ! address of second group (lowbyte)
lda SP+1
adc #0
sta ADDR+3 ! address of second group (highbyte)
1: dey
lda (ADDR),y ! get byte from first group
pha ! temporary save
lda (ADDR+2),y ! get byte from second group
sta (ADDR),y ! store in first group
pla ! get temporary saved byte
sta (ADDR+2),y ! store in second group
tya
bne 1b ! perform n times
rts