[newbie] A<-A+X operation, how to

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
Post Reply
User avatar
waskol
Flight Lieutenant
Posts: 331
Joined: Wed Jun 13, 2007 8:20 pm
Location: FRANCE, Paris

[newbie] A<-A+X operation, how to

Post by waskol » Thu Aug 21, 2008 3:13 am

Well, it is not easy to explain, but I am stuck with this.

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
...
Here is my dumb question : :oops:
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)
Thus, the exact question should be more alike this one : what address should I choose, in the Oric memory, as a temporary variable ???
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
Thanks for help.

(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 !)

User avatar
Twilighte
Game master
Posts: 819
Joined: Sat Jan 07, 2006 12:07 am
Location: Luton, UK
Contact:

Post by Twilighte » Fri Aug 22, 2008 9:18 am

it needn't be so complicated at all 8)
i usually assign a temp variable to zero page then..

Code: Select all

stx temp01
clc
adc temp01
no worries for cld, any routine that uses bcd (cld/sed) always clears bcd at end, or at least should do.

if u use xa for compiling, then..

Code: Select all

 .zero
*=$00
temp01    .dsb 1

 .text
*=$blah blah
under basic, zero page addresses 0 to B, BB-BC and F3 to F9 are not used and may be used by you (the programmer).
if a program is totally machine code and doesn't use basic, then you get all 256 addresses of zero page, page 2, etc. :D

Twi

User avatar
waskol
Flight Lieutenant
Posts: 331
Joined: Wed Jun 13, 2007 8:20 pm
Location: FRANCE, Paris

Post by waskol » Fri Sep 12, 2008 7:34 am

Thanks twi, i did not see your answer before !

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests