<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 24 Nov 2009 08:39:37 +0100 (CET)
From   : anders.carlsson@... (Anders Carlsson)
Subject: Quine

Mick Champion wrote:

> Is the exit carry bit placed on the stack until the value
> in carry bit is written to the shifting byte?

No, the CPU has a status register which holds the flags for
negative, overflow, break, decimal mode, interrupt, zero and
carry bit. One bit is unused.

It means it will retain your carry bit until you execute
another instruction which modifies it. Usually when you read
the list of instructions, there will be a table like this:

N V - B D I Z C
- - - - - - v v

which would mean the instruction will set/clear Z and C flags
accordingly to the result of the instruction. All other flags
would be left untouched. Sometimes the N flag is called S for
Sign.

For example LSR will shift bit 0 into carry and set the zero
flag if the result equals 0. In my previous example INX will
actually also change the zero flag, in such way it will clear
it until X=0 again. This however is not a problem since there
are at most eight bits to a byte. In worst case it means the
loop is run one time more than required without changing the
result. If we had a 256-bit CPU, it would have needed a rewrite.. :)

By the way, if you want to save the current state of the
status register, there are instructions for that too. To begin
with you can PHP (Push Processor or whatever it means) which
puts a copy of the status register on the stack. Then you can
PLA to bring it back to the accumulator for further processing.

Of course you can also PLP which would bring the first value
from the stack into the status register, but it could have
rather interesting results unless you are certain what is on
the stack.

Best regards

-- 
Anders Carlsson
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>