Mine question is about the instruction: "ldaa    state,x" like "staa    state,x" I'm I correct with mine intention, that the index-register as temporary storage, to load and to store, "state" in/from accu a is?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mine question is about the instruction: "ldaa    state,x" like "staa    state,x" I'm I correct with mine intention, that the index-register as temporary storage, to load and to store, "state" in/from accu a is?

1,492 Views
franz_raaber
Contributor II

I'm sorry, but I'm at the moment a little bit confused. Mine question is about the instruction: "ldaa    state,x" like "staa    state,x".

Am I correct with mine intention, that the index-register as temporary storage, to load and to store, "state" in/from accu a is?

 

Yours

Franz

Labels (1)
0 Kudos
4 Replies

493 Views
Derrick
NXP Employee
NXP Employee

The S08 CPU does not have an LDAA instruction, but the HC11 does.  In either case, you are referring to indexed addressing using index register X (XREG).

Using your example of "ldaa   state,x", the parameter "state" will translate to constant value that is added to the (variable) value in XREG to calculate the effective address from whose data will be loaded into the accumulator.

For example, let's assign XREG = 0x25 and consider the following:

state   equ     5

ldaa    state,x

In this case "state" is a constant value and the accumulator is loaded with the value stored at address location 0x002A (i.e., 0x25 + 5).

But, a common error which I see occurs when "state" is declared as a variable, like this:

state   ds     1

In this case "state" is an address location in RAM that is used to store a byte variable.  Let's assume that this address location is 0x0100.  If we assign XREG = 0x25, then the following:

ldaa    state,x

will result in the accumulator being loaded with the value stored at address location 0x0125 (i.e., 0x25 + 0x0100).

I hope that this helps.

Best Regards,

Derrick


0 Kudos

493 Views
franz_raaber
Contributor II

Thank you Derrick for your attempt of explanation, where I have some words to comment.

I handle with an S07 CPU and respectively with an HC11.

So if I understand you in the correct way, then do I understand you explanation as:

ldaa state,x ; i.e. a = [[state] + ]

where the address, of the state-variable value, and the stored address in index-register x are

added, whom sum the memory/RAM addresses, where the stored value of the addressed memory

– by this sum – in the accu a stored will be.

Am I correct with mine explanation of this instruction?

What does in

state ds 1

ds in this instruction mean?

Thank you very much for your explanation

kind regards

Franz

Von: Derrick Klotz

Gesendet: Donnerstag, 05. September 2013 16:06

An: Raaber Franz

Betreff: Re: - Mine question is about the instruction: "ldaa state,x" like "staa state,x" I'm I correct with mine intention, that the index-register as temporary storage, to load and to store, "state" in/from accu a is?

<https://community.freescale.com/>

Mine question is about the instruction: "ldaa state,x" like "staa state,x" I'm I correct with mine intention, that the index-register as temporary storage, to load and to store, "state" in/from accu a is?

reply from Derrick Klotz<https://community.freescale.com/people/Derrick?et=watches.email.thread> in 8-bit Microcontrollers - View the full discussion<https://community.freescale.com/message/348570?et=watches.email.thread#348570>

0 Kudos

493 Views
Derrick
NXP Employee
NXP Employee

Hi Franz,

I think that we are saying the same thing.

Indexed addressing will calculate the effective address by adding a constant and a variable.  The constant is the first parameter and the variable is the X Index Register (XREG).

In your example, "state" is either a declared constant (using "equ") or a memory address location.  If "state" is the memory address location of a variable in RAM, indexed addressing will not read the data stored at that location.  Instead, it will use the address itself as the constant parameter and add to it the variable value in XREG.  In other words, you are using XREG as a variable offset from the memory address location of "state".

"ds" is an old assembly language pseudo op for "data storage".  So "state   ds 1" will assign one byte of RAM to the label "state".  I will admit that it has been a long time since I used this :smileyhappy:.

Best Regards,

Derrick


0 Kudos

493 Views
iansmusical
Contributor V

Hi Franz,

From my understanding of ldaa state,x the instruction will load into accumulator A a value from the combination of the index register x plus the state operand.

For example:       ldaa    5, x

Will take the sum of the value currently in the x register and 5, then load accumulator A with the memory byte at that resultant address.

Does this clarify it for you?

Ian

0 Kudos