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
6502 ALU pseudocode
Re: 6502 ALU pseudocode
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.
http://6502.org/users/dieter/bcd/bcd_0.htm
It's a description of how the 6502 does BCD.
Re: 6502 ALU pseudocode
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
Ref: http://visual6502.org/wiki/index.php?ti ... stPrograms
Re: 6502 ALU pseudocode
ProfJ wrote:
this message editor kills my indenting:
-- Jeff
Code: Select all
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
endIn 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
https://laughtonelectronics.com/Arcana/ ... mmary.html
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: 6502 ALU pseudocode
Dr Jefyll wrote:
To preserve formatting, use the editor's Code style.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: 6502 ALU pseudocode
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.
http://6502.org/users/dieter/bcd/bcd_0.htm
It's a description of how the 6502 does BCD.
Re: 6502 ALU pseudocode
Quote:
The signal names are shown in the standard 6502 block diagram