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

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: 6502 ALU pseudocode
PostPosted: Thu May 30, 2019 6:27 pm 
Offline

Joined: Thu May 30, 2019 5:49 pm
Posts: 2
Hi Folks,

This is my first post on this forum, hope it's in the right place!

I'm trying to write some pseudocode for the 6502 ALU operation. It seems to be straightforward, except for the BCD addition when DAA is high. This is what I have (the variable names come from the block diagram, and I/ADDC is a name, not a division operation). Apologies, this message editor kills my indenting:

if SUM == 1
if DAA==0
[ACR ADD] = AI + BI + I/ADDC
AVR = (AI(7) && BI(7) && ~ADD(7))||(~AI(7) && ~BI(7) && ADD(7))
else
[HC ADD(3:0)] = AI(3:0) + BI(3:0) + I/ADDC
[ACR ADD(7:4)] = AI(7:4) + BI(7:4)
end
end

I'm mainly concerned with how the carry in, and half-carry and carry out work, can anyone tell me if this is correct?

Thanks
Jon


Top
 Profile  
Reply with quote  
 Post subject: Re: 6502 ALU pseudocode
PostPosted: Thu May 30, 2019 7:02 pm 
Offline

Joined: Sun Oct 01, 2017 1:54 pm
Posts: 20
You may want to explain your selection of names. I don't think are common/standard. The DAA input(?) seems like it may have come from 8080 land. But it may just be me; I'm not an '02 guru. Nevertheless, this page linked to on the front page of 6502.org may be of some help:
http://6502.org/users/dieter/bcd/bcd_0.htm
It's a description of how the 6502 does BCD.


Top
 Profile  
Reply with quote  
 Post subject: Re: 6502 ALU pseudocode
PostPosted: Thu May 30, 2019 7:22 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
Welcome Jon! It's (very) tricky to get BCD right, so I know I can't say anything about the correctness of your approach even by careful code reading. Personally I'd inspect the code of any existing core (or emulator) which is open source and passes a suitable testsuite. Have you tried Bruce's decimal test? Or Klaus' full testsuite?
Ref: http://visual6502.org/wiki/index.php?ti ... stPrograms


Top
 Profile  
Reply with quote  
 Post subject: Re: 6502 ALU pseudocode
PostPosted: Thu May 30, 2019 7:28 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
ProfJ wrote:
this message editor kills my indenting:
Welcome! To preserve formatting, use the editor's Code style.

-- Jeff

Code:
    if SUM == 1
        if DAA==0
      [ACR ADD] = AI + BI + I/ADDC
      AVR = (AI(7) && BI(7) && ~ADD(7))||(~AI(7) && ~BI(7) && ADD(7))
      else
      [HC ADD(3:0)] = AI(3:0) + BI(3:0) + I/ADDC
      [ACR ADD(7:4)] = AI(7:4) + BI(7:4)
      end
   end

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: 6502 ALU pseudocode
PostPosted: Thu May 30, 2019 7:51 pm 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8540
Location: Southern California
Dr Jefyll wrote:
To preserve formatting, use the editor's Code style.

Yes, put your code between the tags [code] and [/code]. (I did something else here to keep them from taking effect.)

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: 6502 ALU pseudocode
PostPosted: Thu May 30, 2019 9:35 pm 
Offline

Joined: Thu May 30, 2019 5:49 pm
Posts: 2
bdk6 wrote:
You may want to explain your selection of names. I don't think are common/standard. The DAA input(?) seems like it may have come from 8080 land. But it may just be me; I'm not an '02 guru. Nevertheless, this page linked to on the front page of 6502.org may be of some help:
http://6502.org/users/dieter/bcd/bcd_0.htm
It's a description of how the 6502 does BCD.


Thanks for that link. The signal names are shown in the standard 6502 block diagram, see for example here http://www.weihenstephan.org/~michaste/ ... 2/6502.jpg .


Top
 Profile  
Reply with quote  
 Post subject: Re: 6502 ALU pseudocode
PostPosted: Thu May 30, 2019 10:23 pm 
Offline

Joined: Sun Oct 01, 2017 1:54 pm
Posts: 20
Quote:
The signal names are shown in the standard 6502 block diagram

Yeah, sorry about that. I was preoccupied when I first read your post and only got about half the information. I do think it would be useful to have put a link to that block diagram in the post for morons like me. I realized right after I commented that you mentioned it. I was gonna be quiet and hope nobody noticed :oops:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 12 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: