]> git.sur5r.net Git - cc65/commitdiff
New functions to swap register variables
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 25 Nov 2002 12:38:38 +0000 (12:38 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 25 Nov 2002 12:38:38 +0000 (12:38 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1629 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/runtime/Makefile
libsrc/runtime/regswap.s [new file with mode: 0644]
libsrc/runtime/regswap1.s [new file with mode: 0644]
libsrc/runtime/regswap2.s [new file with mode: 0644]

index ede6e75129ac16f7ca1cbda4b35be5ccb3cdcc51..4e0a20bfab0929e6784152859d2a5dfe2cac91c0 100644 (file)
@@ -159,6 +159,9 @@ OBJS =      add.o           \
        pushlysp.o      \
                pushw.o         \
                pushwsp.o       \
+        regswap.o       \
+        regswap1.o      \
+        regswap2.o      \
        return0.o       \
        return1.o       \
                rsub.o          \
diff --git a/libsrc/runtime/regswap.s b/libsrc/runtime/regswap.s
new file mode 100644 (file)
index 0000000..28e0441
--- /dev/null
@@ -0,0 +1,28 @@
+;
+; Ullrich von Bassewitz, 25.11.2002
+;
+; CC65 runtime: Swap x bytes of register variable space
+;
+
+       .export         regswap
+       .importzp       sp, regbank, tmp1
+
+.proc  regswap
+
+        sta     tmp1                    ; Store count
+@L1:    lda     regbank,x               ; Get old value
+        pha                             ; Save it
+        lda     (sp),y                  ; Get stack loc
+        sta     regbank,x               ; Store new value
+        pla
+        sta     (sp),y                  ; Store old value
+        inx
+        iny
+        dec     tmp1
+        bne     @L1
+
+       rts
+
+.endproc
+
+
diff --git a/libsrc/runtime/regswap1.s b/libsrc/runtime/regswap1.s
new file mode 100644 (file)
index 0000000..e2410f9
--- /dev/null
@@ -0,0 +1,22 @@
+;
+; Ullrich von Bassewitz, 25.11.2002
+;
+; CC65 runtime: Swap 1 byte of register variable space
+;
+
+       .export         regswap1
+       .importzp       sp, regbank
+
+.proc  regswap1
+
+        lda     regbank,x               ; Get old value
+        pha                             ; Save it
+        lda     (sp),y                  ; Get stack loc
+        sta     regbank,x               ; Store new value
+        pla
+        sta     (sp),y                  ; Store old value
+       rts
+
+.endproc
+
+
diff --git a/libsrc/runtime/regswap2.s b/libsrc/runtime/regswap2.s
new file mode 100644 (file)
index 0000000..50eb6c2
--- /dev/null
@@ -0,0 +1,35 @@
+;
+; Ullrich von Bassewitz, 25.11.2002
+;
+; CC65 runtime: Swap 2 bytes of register variable space
+;
+
+       .export         regswap2
+       .importzp       sp, regbank
+
+.proc  regswap2
+
+; First byte
+
+        lda     regbank,x               ; Get old value
+        pha                             ; Save it
+        lda     (sp),y                  ; Get stack loc
+        sta     regbank,x               ; Store new value
+        pla
+        sta     (sp),y                  ; Store old value
+
+; Second byte
+
+        iny
+        lda     regbank+1,x             ; Get old value
+        pha                             ; Save it
+        lda     (sp),y                  ; Get stack loc
+        sta     regbank+1,x             ; Store new value
+        pla
+        sta     (sp),y                  ; Store old value
+
+       rts
+
+.endproc
+
+