Signed 16-bit right shift question with -1 shift check
Re: Signed 16-bit right shift question with -1 shift check
No, adding 1 before shifting doesn't work. If the dividend is -1, it is set to zero. The carry flag is still set from the test of the sign bit so when the number is shifted, the result returned is -32768.
Re: Signed 16-bit right shift question with -1 shift check
Hi!
You are right, this should work:
JimBoyd wrote:
No, adding 1 before shifting doesn't work. If the dividend is -1, it is set to zero. The carry flag is still set from the test of the sign bit so when the number is shifted, the result returned is -32768.
Code: Select all
.macro div2_16bit(address) {
ldy address + 1
bpl ok
inc address +0
bne ok
iny
ok:
cpy #$80
tya
ror
ror address + 0
sta address + 1
}
Re: Signed 16-bit right shift question with -1 shift check
dmsc wrote:
You are right, this should work:
Re: Signed 16-bit right shift question with -1 shift check
Here's my attempt, which just special-cases the -1 case:
Code: Select all
.Div16_2
LDA address
AND address+1
INC A ; turns 0xFFFF into zero, anything else will be non-zero
BNE Shift16
STA address ; explicitly store a zero result
STA address+1
BEQ End
.Shift16
LDA address+1
ASL A
ROR address+1
ROR address
.End
-
paul_nicholls
- Posts: 42
- Joined: 19 Jan 2011
- Contact:
Re: Signed 16-bit right shift question with -1 shift check
Thanks for all the answers everyone, much appreciated 
I think I'm good now
cheers,
Paul
I think I'm good now
cheers,
Paul
"The plastic veneer of civilization is easily melted in the heat of the moment" - Paul Nicholls