2000-05-28 13:40:48 +00:00
|
|
|
;
|
2004-07-05 22:24:06 +00:00
|
|
|
; Ullrich von Bassewitz, 2004-06-30
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2004-07-05 22:24:06 +00:00
|
|
|
; CC65 runtime: right shift support for unsigned longs
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2004-07-05 22:24:06 +00:00
|
|
|
; Note: The standard declares a shift count that is negative or >= the
|
|
|
|
; bitcount of the shifted type for undefined behaviour.
|
|
|
|
;
|
|
|
|
; Note^2: The compiler knowns about the register/zero page usage of this
|
|
|
|
; function, so you need to change the compiler source if you change it!
|
|
|
|
;
|
|
|
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export tosshreax
|
|
|
|
.import popeax
|
|
|
|
.importzp sreg, tmp1
|
2004-07-05 22:24:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
tosshreax:
|
|
|
|
and #$1F ; Bring the shift count into a valid range
|
|
|
|
sta tmp1 ; Save it
|
|
|
|
|
|
|
|
jsr popeax ; Get the left hand operand
|
|
|
|
|
|
|
|
ldy tmp1 ; Get shift count
|
|
|
|
beq L9 ; Bail out if shift count zero
|
|
|
|
stx tmp1 ; Save byte 1
|
|
|
|
|
|
|
|
; Do the actual shift. Faster solutions are possible but need a lot more code.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
L2: lsr sreg+1
|
2013-05-09 11:56:54 +00:00
|
|
|
ror sreg
|
|
|
|
ror tmp1
|
2004-07-05 22:24:06 +00:00
|
|
|
ror a
|
|
|
|
dey
|
2013-05-09 11:56:54 +00:00
|
|
|
bne L2
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
; Shift done
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
ldx tmp1
|
|
|
|
L9: rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|