Date : Tue, 24 Nov 2009 13:21:22 +0000
From : rs423@... (Mick Champion)
Subject: Quine
Anders Carlsson wrote:
> 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.
>
I not quite sure what to say as now finally the penny has dropped, I'm
feeling quite foolish. I was getting confused because I wrongly thought
a ROL would transfer bit 7 to the carry first, followed by bit 6 to bit
7, 5 to 6, repeat until the carry flag state is written intoto bit 0. I
therefore thought the carry shifted out was the one shifted in. Wrong !
Doh!! Not just from typing in ;
CLC
ASL &4010
ROL &4011
ROL &4012
I now fully understand by way of the carry flag, that (ASL) &4010 bit 7
becomes (ROL) &4011 bit 0, and &4011 bit 7 >>(ROL)&4012 bit 0.
Whichever way it does it I realise (NOW) that the carry flag status is
read and written to the byte before being changed on exit. It really
does make a lot more sense this way. Why I couldn't get to grips with it
before I don't know. Phew!!!
> 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.
>
Thanks. That was something else I haven't played with that I really
should have.
So instead of ;
.carry
LDX#0
BCC carry2 // check carry and
LDX#1 // make X=1 if set
.carry2
ASL &4011 // shift hi byte left then
CLC
TXA // add the carry stored in X after the shift
ADC &4011
STA &4011
RTS
I could have done ;
.carry
PHP /// save flags expecially carry
ASL &4011 /// could change carry flag
PLA /// return old flags
LDA & 4011
ADC#0 /// add with carry as set before the ASL
STA &4011
RTS
Not that I would ever need to use this program now I know how to use
ASL's and ROL's!!!
> 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.
>
I think I'll give that a miss if it's all the same to you ;-) .
Cheers,
Mick