[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ADC & SBC OpCodes Questions
- Subject: Re: ADC & SBC OpCodes Questions
- From: dempson@actrix.gen.nz (David Empson)
- Date: Fri, 24 May 2002 00:49:27 +1200
- Newsgroups: comp.sys.apple2
- Organization: Empsoft
- References: <nUXG8.106640$Ze4.11231712@bin5.nnrp.aus1.giganews.com>
- User-agent: MacSOUP/2.4.2
- Xref: archiver1.google.com comp.sys.apple2:19839
Bryan Parkoff <BParkoff@satx.rr.com> wrote:
> ADC & SBC OpCodes Questions
>
> I remembered that we discussed the difference between 65816 and Intel
> instructions. Again, we remembered discussing the two opcodes -- ADC and
> SBC.
I don't recall seeing any such discussion in comp.sys.apple2 in recent
months. I don't read comp.emulators.apple2, so I'm unaware of any such
discussion which might have occurred there.
> I understand why each emulator projects are required to write several
> lines inside one function to emulate ADC and SBC opcodes properly through
> C++. Please explain again one more time why it is necessary. The simple
> function is to accumulate one byte before adds or subtracts second byte into
> final one byte. For example, it should look like
>
> unsigned char A = 0x40;
> unsigned char B = 0x4C;
> unsigned char C = A + B;
>
> Final one byte -- C should always displays 0x8C.
That is correct, assuming:
1. The carry flag was clear before the ADC instruction. (If the carry
flag is set, it is necessary to add 1 more.)
2. The decimal mode flag is clear.
(If the decimal mode flag is set, the result of the above addition is
not officially defined, because 0xC is not a valid decimal number.)
3. If this is a 65816 emulator, there would also need to be code to deal
with the size of the accumulator (8 bit or 16 bit).
There would also need to be code to derive the appropriate values for
the N, V, Z and C flags after the ADC or SBC.
SBC may also require some extra steps to deal with the inverted carry
flag. (I think the real 6502 does something like complement one of the
inputs, do an ADC in the ALU, and then adjust the result. This reduced
the number of gates required in the ALU, as it only has to implement an
add operation, not a subtract.)
> Why ADC and SBC functions have to separate byte into two nibbles before they
> can do operations.
If the CPU is operating in binary mode, I can't see any reason for doing
that. If the CPU is operating in decimal mode, then it is probably
easier to add the two digits separately and then calculate the correct
result from the two partial results.
--
David Empson
dempson@actrix.gen.nz