]> git.sur5r.net Git - cc65/commitdiff
Rewrite to add an entry point for shraxy that doesn't need to pass values over
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 6 Jul 2012 19:57:24 +0000 (19:57 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 6 Jul 2012 19:57:24 +0000 (19:57 +0000)
the stack.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5761 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/runtime/shr.s

index 3b505e74dbe6002102c404a01302e0c5910a30e3..edc5f871c7a3d735e5557e7ad7fa5c4e4b6f9e5f 100644 (file)
 ;
 
 
-       .export         tosshrax
+       .export         tosshrax, shraxy
        .import         popax
        .importzp       tmp1
 
 tosshrax:
-        and     #$0F            ; Bring the shift count into a valid range
-        sta     tmp1            ; Save it
-
+        sta     tmp1            ; Save shift count
         jsr     popax           ; Get the left hand operand
-
         ldy     tmp1            ; Get shift count
-        beq     L9              ; Bail out if shift count zero
 
-        cpy     #8              ; Shift count 8 or greater?
-        bcc     L3              ; Jump if not
-
-; Shift count is greater 7. The carry is set when we enter here.
+; Run into shraxy
 
+shraxy:
+        pha
         tya
-        sbc     #8
-        tay                     ; Adjust shift count
-        txa
-        ldx     #$00            ; Shift by 8 bits
-        beq     L2              ; Branch always
+        and     #$0F
+        beq     L2              ; Nothing to shift
+        sec
+        sbc     #8              ; Shift count 8 or greater?
+        beq     L3              ; Jump if exactly 8
+        bcc     L4              ; Jump if less than 8
+
+; Shift count is greater than 8.
+
+        tay                     ; Shift count into Y
+        pla                     ; Discard low byte
+        txa                     ; Get high byte
+
 L1:     lsr     a
-L2:     dey
-        bpl     L1
+        dey
+        bne     L1
+        ldx     #$00            ; High byte is zero
         rts
 
-; Shift count is less than 8. Do the actual shift.
+; Shift count is zero
 
-L3:     stx     tmp1            ; Save high byte of lhs
-L4:     lsr     tmp1
+L2:     pla
+        rts
+
+; Shift count is exactly 8
+
+L3:     pla                     ; Drop low byte from stack ...
+        txa                     ; Move high byte to low
+        ldx     #$00            ; Clear high byte
+        rts
+
+; Shift count is less than 8
+
+L4:     adc     #8              ; Correct counter
+        tay                     ; Shift count into Y
+        pla                     ; Restore low byte
+        stx     tmp1            ; Save high byte of lhs
+L5:     lsr     tmp1
         ror     a
         dey
-               bne     L4
+               bne     L5
 
 ; Done with shift
 
         ldx    tmp1
-L9:     rts
+        rts
+