fix code for bitwise shifts by zero

This commit is contained in:
Irmen de Jong 2023-08-14 21:49:13 +02:00
parent f98ee326b4
commit be06d871b6
2 changed files with 38 additions and 18 deletions

View File

@ -847,67 +847,79 @@ mul_word_640 .proc
; support for bit shifting that is too large to be unrolled:
lsr_byte_A .proc
; -- lsr signed byte in A times the value in Y (>1)
; -- lsr signed byte in A times the value in Y
cpy #0
beq +
cmp #0
bpl lsr_ubyte_A
- sec
ror a
dey
bne -
rts
+ rts
.pend
lsr_ubyte_A .proc
; -- lsr unsigned byte in A times the value in Y (>1)
; -- lsr unsigned byte in A times the value in Y
cpy #0
beq +
- lsr a
dey
bne -
rts
+ rts
.pend
asl_byte_A .proc
; -- asl any byte in A times the value in Y (>1)
; -- asl any byte in A times the value in Y
cpy #0
beq +
- asl a
dey
bne -
rts
+ rts
.pend
lsr_word_AY .proc
; -- lsr signed word in AY times the value in X (>1)
; -- lsr signed word in AY times the value in X
cpx #0
beq +
cpy #0
bpl lsr_uword_AY
sty P8ZP_SCRATCH_B1
_negative sec
- sec
ror P8ZP_SCRATCH_B1
ror a
dex
bne _negative
bne -
ldy P8ZP_SCRATCH_B1
rts
+ rts
.pend
lsr_uword_AY .proc
; -- lsr unsigned word in AY times the value in X (>1)
; -- lsr unsigned word in AY times the value in X
cpx #0
beq +
sty P8ZP_SCRATCH_B1
- lsr P8ZP_SCRATCH_B1
ror a
dex
bne -
ldy P8ZP_SCRATCH_B1
rts
+ rts
.pend
asl_word_AY .proc
; -- asl any word in AY times the value in X (>1)
; -- asl any word in AY times the value in X
cpx #0
beq +
sty P8ZP_SCRATCH_B1
- asl a
rol P8ZP_SCRATCH_B1
dex
bne -
ldy P8ZP_SCRATCH_B1
rts
+ rts
.pend

View File

@ -1,8 +1,16 @@
%import textio
%zeropage basicsafe
main {
sub start() {
print('@')
}
sub print(str message) {
ubyte value = 1
uword wvalue = 1
ubyte zero = 0
txt.print_ub(value<<zero) ; TODO fix result 6502 codegen! should be 1.
txt.print_uw(wvalue<<zero) ; TODO fix result 6502 codegen! should be 1.
ubyte value2 = value<<zero ; result is ok, 1
uword wvalue2 = wvalue<<zero ; result is ok, 1
txt.print_ub(value2)
txt.print_uw(wvalue2)
}
}