6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 10:56 pm

All times are UTC




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Tue Oct 09, 2018 7:21 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
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.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 10, 2018 9:15 pm 
Offline

Joined: Mon Sep 17, 2018 2:39 am
Posts: 138
Hi!

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.


You are right, this should work:

Code:
.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
}


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 12, 2018 8:56 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
dmsc wrote:
You are right, this should work:

It does. As Mike said, well done!


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 15, 2018 9:53 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Here's my attempt, which just special-cases the -1 case:
Code:
.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


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 16, 2018 6:50 am 
Offline

Joined: Wed Jan 19, 2011 10:20 pm
Posts: 42
Thanks for all the answers everyone, much appreciated :)

I think I'm good now :D

cheers,
Paul

_________________
"The plastic veneer of civilization is easily melted in the heat of the moment" - Paul Nicholls


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: