Suppose that a value was previously stored in the accumulator (A) another one in the X register, for instance
Code: Select all
LDA #$03
LDX #$02
...
What is the best method in order to add A and X ?
I well understood that there was no "implicit" way to do it with the ADC instruction, and that I am obliged to use a temporary memory location, like this :
Code: Select all
;A<-A+X
CLC
CLD
LDA #$03
LDX #$02
STX temp ;store X in temp memory location
ADC temp ;Add temp to A (result in A)
I imagine that it is not well indicated to choose a zero page address, or am I wrong ?
May be I could use the stack, but how ? For example,is this correct ?
Code: Select all
;A<-A+X
CLC
CLD
LDA #$03
LDX #$02
PHA ;push A on the stack
TXA ;move X to A
TSX ;move address of the stack in X
ADC $00,X ;use X as index in order to add what is contained on the stack to A
;(hum, is this allowed ???? lol )
;what follows does not really matters to me
STA result ;result is a memory location
PLA ;Pop A, let's be clean
(For info, I am trying to build a simple pascal cross compiler for Oric, with Crenshaw's tutorial : http://crenshaw.books.myprojects.kostigoff.net , do not except something terrific !)